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

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

问题描述

(请参阅下面的编辑。)



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



我正在使用maven依赖关系进行antrun调用,遵循maven站点上的文档:



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 =我的依赖关系JAR-Path:$ {mvn.dependency.jar}/>

无论我如何尝试,我都无法做到这一点。我试过$ {}围绕refid内容,我尝试了冒号,句点等。作为分隔符,我可以想到的每一种方式。



任何人告诉我,真正的应该是真的看起来像一些常见的依赖关系?



编辑:



感谢您的回复。



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

  ;插件> 
< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-antrun-plugin< / artifactId>
<执行>
< execution>
< id> create-messages< / id>
< phase> compile< / phase>
< configuration>
< tasks>
< property name =build.compilervalue =extJavac/>
< property name =compile_classpathrefid =maven.compile.classpath/>
< property name =runtime_classpathrefid =maven.runtime.classpath/>
< property name =test_classpathrefid =maven.test.classpath/>
< property name =plugin_classpathrefid =maven.plugin.classpath/>

< property name =log4j.jarrefid =log4j:log4j:jar/>
< echo message =Log4J JAR在哪里?:$ {log4j.jar}/>
< / tasks>
< / configuration>
< goals>
< goal>运行< / goal>
< / goals>
< / execution>
< / executions>
<依赖关系>
<依赖关系>
< groupId> log4j< / groupId>
< artifactId> log4j< / artifactId>
< version> 1.2.14< / version>
< / dependency>
< / dependencies>
< / plugin>

这是运行mvn编译时所得到的:

  [INFO]扫描项目... 
[INFO] --------------------- -------------------------------------------------- -
[INFO]构建聊天组件
[INFO] task-segment:[compile]
[INFO] ------------------ -------------------------------------------------- ----
下载:http://< redacted> /content/groups/public/log4j/log4j/1.2.14/log4j-1.2.14.pom
2K下载
下载:http://< redacted> /content/groups/public/log4j/log4j/1.2.14/log4j-1.2.14.jar
358K下载
[INFO] [antrun:run {执行:create-messages}]
[INFO]执行任务
[INFO] --------------------------- ---------------------------------------------
[错误] BUILD ERROR
[INFO] --------------------------------------- ---------------------------------
[INFO]执行蚂蚁任务时出错

嵌入式错误:引用log4j:log4j:jar没有foun天。
[INFO] ------------------------------------------- -----------------------------
[INFO]有关详细信息,请使用-e开关$ b $运行Maven b [INFO] ---------------------------------------------- --------------------------
[INFO]总时间:3秒
[INFO]完成日期:Fri Oct 16 14:54:19 PDT 2009
[INFO] Final Memory:7M / 80M
[INFO] ---------------------- --------------------------------------------------

编辑(2):



查看源代码链接我决定运行mvn -X compile和grep为存储,这会产生一堆日志输出,其中存储的东西。



感兴趣的是我明确指定的依赖关系不在列表中显示的事实,当我根据其中一个条目切换到一个密钥时,看到,我还是得到错误。

解决方案

根据SingleShot链接的代码,和随机戳戳直到它工作,这里是我如何得到这个问题工作(我用引号说,因为它感觉很脆弱。)



这样做的方式正确工作:

 < property name =log4j_location
value =$ {maven.dependency.log4j。 log4j.jar.path}/>
< echo message =$ {log4j_location}/>一些重要的事情要注意:你不能使用maven依赖关系作为一个...在设置蚂蚁属性时重新设置。您必须使用$ {}获取maven var值。



似乎依赖关系必须在顶级依赖列表中,使得log4j是antrun插件不会暴露给插件,无论如何我可以看到。



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





strong> Soapbox:



我强烈建议任何人考虑使用Ant与maven插件,甚至更好地使用Ant与Ivy。



这个特别的问题是一个闪闪发光的例子,它与使用maven做出任何规范相关的难度级别很难。



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



Maven确实解决了一些蚂蚁不是隐含地解决的东西,但是有一些前期计划,蚂蚁是更灵活,更好的记录,更少的工具。



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



我认为你最终会比Maven快乐,因为你不会花费时间来修复你的构建系统。


(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.

Soapbox:

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

This particular problem is a shining example of the utterly absurd level of difficulty associated with doing anything out of the norm with 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 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).

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天全站免登陆