问题描述
(请参见下面的编辑。)
我不能只使用类路径的原因,是因为我需要管理一些非Java库,而且我编译非Java项目。
我想在antrun呼叫使用Maven依赖关系,在Maven站点文档如下:
http://maven.apache.org/plugins/maven-antrun-plugin/examples/classpaths.html
在页面的底部:
<属性名=mvn.dependency.jar
REFID =maven.dependency.my.group.id:my.artifact.id:classifier:jar.path/>
<回声消息=我的依赖JAR路径:$ {} mvn.dependency.jar/>
我无法使这项工作,无论我如何努力。我试过$ {}周围的REFID内容,我试过冒号,句号等。在每一个方式,我能想到的分隔符。
谁能告诉我这是什么REFID应的真正的样子了一些常见的依赖?
编辑:
感谢您的答复。
使用你的榜样SingleShot,我有以下几点:
<&插件GT;
<&插件GT;
<&的groupId GT; org.apache.maven.plugins< /的groupId>
<&的artifactId GT;的maven-antrun-插件< / artifactId的>
<&执行GT;
<执行与GT;
<&ID GT;创建的消息< / ID>
<阶段>&编译LT; /阶段>
<结构>
<任务和GT;
<属性名=build.compilerVALUE =extJavac/>
<属性名=compile_classpathREFID =maven.compile.classpath/>
<属性名=runtime_classpathREFID =maven.runtime.classpath/>
<属性名=test_classpathREFID =maven.test.classpath/>
<属性名=plugin_classpathREFID =maven.plugin.classpath/> <属性名=log4j.jarREFID =的log4j:log4j的:坛子/>
<回声消息=哪里是Log4J的JAR?:$ {} log4j.jar/>
< /任务>
< /结构>
<目标>
<&目标GT;运行< /目标>
< /目标>
< /执行>
< /处决>
<依赖和GT;
<&依赖性GT;
<&的groupId GT;的log4j< /的groupId>
<&的artifactId GT;的log4j< / artifactId的>
<&版GT; 1.2.14< /版本>
< /依赖性>
< /依赖和GT;
< /插件>
和这里就是我得到运行时编译MVN:
[信息]扫描项目...
[INFO] ----------------------------------------------- -------------------------
[INFO]大厦聊天组件
[INFO]任务段:[编译]
[INFO] ----------------------------------------------- -------------------------
下载:HTTP://<&删节GT; /content/groups/public/log4j/log4j/1.2.14/log4j-1.2.14.pom
2K下载
下载:HTTP://<&删节GT; /content/groups/public/log4j/log4j/1.2.14/log4j-1.2.14.jar
358K下载
[INFO] [antrun:运行{执行:创建的消息}]
[INFO]执行任务
[INFO] ----------------------------------------------- -------------------------
[错误] BUILD ERROR
[INFO] ----------------------------------------------- -------------------------
[INFO]错误执行的Ant任务嵌入式错误:参考的log4j:log4j的:坛子没找到。
[INFO] ----------------------------------------------- -------------------------
[信息]欲了解更多信息,与-e开关运行Maven
[INFO] ----------------------------------------------- -------------------------
[INFO]总时间:3秒
[INFO]在表面处理:周五10月16日14时54分十九秒PDT 2009年
[INFO]最后的内存:7M / 80M
[INFO] ----------------------------------------------- -------------------------
修改(2):
查看源$ C $ C挂我决定运行命令mvn -X编译和grep为存储,它变成了一堆,其中越来越存放东西的输出日志。
有趣的是,我明确指定的依赖并不在列表中显示的事实,而且,当我切换到一个关键的基础上的一个条目我的不的看到,我仍然得到错误。
根据上code,它SingleShot联系,并随机戳,直到它的工作,这里就是我得到了这个问题的工作,(我说的引号是因为它感觉很脆弱。)
下面是做它的方式正常工作:
<属性名=log4j_location
值=$ {} maven.dependency.log4j.log4j.jar.path/>
<回声消息=$ {} log4j_location/>
一些重要的事情需要注意:你的无法的使用Maven的依赖作为REFID在设置Ant属性。你必须使用$ {}来获取Maven的VAR值。
看来,依赖必须在顶级依赖关系列表,使得Log4j提供的antrun插件的依赖并不将其暴露在插件反正,我可以看到。
所有的路径分隔符是点,没有冒号()(:)这就是为什么我最终检查了我自己的答案是正确
。(See edits below.)
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.
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
At the bottom of the page:
<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}"/>
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.
Can anyone tell me what that refid should really look like for some common dependency?
EDIT:
Thanks for your reply.
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>
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] ------------------------------------------------------------------------
EDIT (2):
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.
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}"/>
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.
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的Antrun和相关性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!