Maven Antrun 和依赖 [英] Maven Antrun and Dependencies

查看:32
本文介绍了Maven Antrun 和依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(请参阅下面的修改.)

我不能只使用类路径的原因,是因为我需要管理一些非 java 库,而且我正在编译一个非 java 项目.

The reason I can't just use the classpath, is because I need to manage some non-java libraries, and I'm compiling a non-java project.

我正在尝试在 antrun 调用中使用 maven 依赖项,遵循 maven 站点上的文档:

I'm trying to use maven dependencies in an antrun call, following the documentation on the maven site:

http://maven.apache.org/plugins/maven-antrun-plugin/examples/classpaths.html

在页面底部:

<property name="mvn.dependency.jar" 
      refid="maven.dependency.my.group.id:my.artifact.id:classifier:jar.path"/>
<echo message="My Dependency JAR-Path: ${mvn.dependency.jar}"/> 

无论我怎么努力,我都无法完成这项工作.我在 refid 内容周围尝试过 ${},也尝试过将冒号、句点等用作我能想到的各种方式的分隔符.

I can't make this work no matter how I try. I've tried ${} around the refid contents, I've tried colons, periods, etc.. as separators in every way I can think of.

谁能告诉我对于一些常见的依赖项,refid真正应该是什么样子的?

Can anyone tell me what that refid should really look like for some common dependency?

感谢您的回复.

使用您的示例 SingleShot,我有以下内容:

Using your example SingleShot, I have the following:

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
      <execution>
        <id>create-messages</id>
        <phase>compile</phase>
        <configuration>
          <tasks>
            <property name="build.compiler" value="extJavac"/>
            <property name="compile_classpath" refid="maven.compile.classpath"/>
            <property name="runtime_classpath" refid="maven.runtime.classpath"/>
            <property name="test_classpath" refid="maven.test.classpath"/>
            <property name="plugin_classpath" refid="maven.plugin.classpath"/>

            <property name="log4j.jar" refid="log4j:log4j:jar"/>
            <echo message="Where is the Log4J JAR?: ${log4j.jar}"/>
          </tasks>
        </configuration>
        <goals>
          <goal>run</goal>
        </goals>
      </execution>
    </executions>
    <dependencies>
      <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.14</version>
      </dependency>
    </dependencies>
  </plugin>

这是我在运行 mvn compile 时得到的:

And here's what I get when run mvn compile:

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Chat Component
[INFO]    task-segment: [compile]
[INFO] ------------------------------------------------------------------------
Downloading: http://<redacted>/content/groups/public/log4j/log4j/1.2.14/log4j-1.2.14.pom
2K downloaded
Downloading: http://<redacted>/content/groups/public/log4j/log4j/1.2.14/log4j-1.2.14.jar
358K downloaded
[INFO] [antrun:run {execution: create-messages}]
[INFO] Executing tasks
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error executing ant tasks

Embedded error: Reference log4j:log4j:jar not found.
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3 seconds
[INFO] Finished at: Fri Oct 16 14:54:19 PDT 2009
[INFO] Final Memory: 7M/80M
[INFO] ------------------------------------------------------------------------

编辑 (2):

查看链接的源代码,我决定运行mvn -X compile"和存储"的grep,这会在存储内容的地方显示一堆日志输出.

Looking at the sourcecode linked I decided to run "mvn -X compile" and grep for "Storing", which turns up a bunch of log output where things are getting stored.

有趣的是,我明确指定的依赖项没有显示在列表中,而且当我根据我确实看到的条目之一切换到一个键时,我仍然收到错误.

Of interest are the facts that the dependency I'm explicitly specifying isn't showing in the list, and, that when I switch to a key based on one of the entries I do see, I still get the error.

推荐答案

基于 SingleShot 链接到的代码,并随机戳直到它工作,这就是我如何解决这个问题工作",(我用引号说,因为它感觉很脆弱.)

Based on the code that SingleShot linked to, and random poking until it worked, here's how I got this problem "working", (I say in quotes because it feels very tenuous.)

以下是使其正常工作的方法:

Here's the way to make it properly work:

<property name="log4j_location" 
                value="${maven.dependency.log4j.log4j.jar.path}"/>
<echo message="${log4j_location}"/>

需要注意的一些重要事项:您不能使用 maven 依赖项作为设置 ant 属性的 refid.您必须使用 ${} 来获取 maven var 值.

Some important things to note: You cannot use the maven dependency as a refid in setting the ant property. You have to use ${} to get the maven var value.

看来依赖必须在顶级依赖列表中,使 log4j 成为 antrun 插件的依赖并不会以我能看到的任何方式将其暴露给插件.

It appears that the dependency must be in the top-level dependency list, making log4j a dependency of the antrun plugin does not expose it to the plugin in anyway that I can see.

所有路径分隔符都是点 (.),没有冒号 (:) 这就是为什么我最终检查自己的答案是正确的.

All of the path separators are dots (.), no colons (:) which is why I ultimately checked my own answer as correct.

肥皂盒:

我强烈推荐任何考虑 Maven 的人使用 Ant 和 maven 插件,或者更好的是,使用 Ant 和 Ivy.

I would highly recommend anyone considering Maven use Ant with maven plugins or, even better, use Ant with Ivy instead.

这个特殊的问题是一个光辉的例子,说明使用 maven 做任何不符合规范的事情会带来极其荒谬的难度.

This particular problem is a shining example of the utterly absurd level of difficulty associated with doing anything out of the norm with maven.

我说这是基于 Maven2 实现了一个完整的构建系统,并且还在 Ant 中实现了几个构建系统.我已经将 Maven2 和 Ant 用于涉及 Java、Flex/AS3、C# 和 C++ 的复杂构建.对于没有对其他语言项目的外部依赖的Java项目,Maven 很有意义.

I say this having implemented an entire build system based on Maven2, and having also implemented several build systems in Ant. I've used both Maven2 and Ant with complex builds involving Java, Flex/AS3, C# and C++. Maven makes sense for Java projects that have no external dependencies on projects in other languages.

Maven 确实解决了 Ant 未隐式解决的一些问题,但通过一些预先规划,Ant 是更灵活、文档更好、错误更少的工具.

Maven does address some things that aren't addressed implicitly by Ant, but with some up front planning, Ant is the much more flexible, better documented, and the less buggy tool.

如果您决定走蚂蚁路线,请确保为您的项目定义一个结构,找出您的依赖系统(使用一个).

If you decide to go the ant route, make sure to define a structure for your projects, figure out your dependency system (Use one).

我认为你最终会比使用 Maven 更快乐,因为你不会花紧要时间试图修复你的构建系统.

I think you will ultimately be much happier than with Maven, as you won't spend crunch time trying to fix your build system.

这篇关于Maven Antrun 和依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆