Maven的Antrun和相关性 [英] Maven Antrun and Dependencies

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

问题描述

(请参见下面的编辑。)

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

我想在antrun呼叫使用Maven依赖关系,在Maven站点文档如下:

<一个href=\"http://maven.apache.org/plugins/maven-antrun-plugin/examples/classpaths.html\">http://maven.apache.org/plugins/maven-antrun-plugin/examples/classpaths.html

在页面的底部:

 &LT;属性名=mvn.dependency.jar
      REFID =maven.dependency.my.group.id:my.artifact.id:classifier:jar.path/&GT;
&LT;回声消息=我的依赖JAR路径:$ {} mvn.dependency.jar/&GT;

我无法使这项工作,无论我如何努力。我试过$ {}周围的REFID内容,我试过冒号,句号等。在每一个方式,我能想到的分隔符。

谁能告诉我这是什么REFID应的真正的样子了一些常见的依赖?

编辑:

感谢您的答复。

使用你的榜样SingleShot,我有以下几点:

 &LT;&插件GT;
  &LT;&插件GT;
    &LT;&的groupId GT; org.apache.maven.plugins&LT; /的groupId&GT;
    &LT;&的artifactId GT;的maven-antrun-插件&LT; / artifactId的&GT;
    &LT;&执行GT;
      &LT;执行与GT;
        &LT;&ID GT;创建的消息&LT; / ID&GT;
        &LT;阶段&gt;&编译LT; /阶段&gt;
        &LT;结构&gt;
          &LT;任务和GT;
            &LT;属性名=build.compilerVALUE =extJavac/&GT;
            &LT;属性名=compile_classpathREFID =maven.compile.classpath/&GT;
            &LT;属性名=runtime_classpathREFID =maven.runtime.classpath/&GT;
            &LT;属性名=test_classpathREFID =maven.test.classpath/&GT;
            &LT;属性名=plugin_classpathREFID =maven.plugin.classpath/&GT;            &LT;属性名=log4j.jarREFID =的log4j:log4j的:坛子/&GT;
            &LT;回声消息=哪里是Log4J的JAR?:$ {} log4j.jar/&GT;
          &LT; /任务&GT;
        &LT; /结构&gt;
        &LT;目标&GT;
          &LT;&目标GT;运行&LT; /目标&GT;
        &LT; /目标&GT;
      &LT; /执行&GT;
    &LT; /处决&GT;
    &LT;依赖和GT;
      &LT;&依赖性GT;
        &LT;&的groupId GT;的log4j&LT; /的groupId&GT;
        &LT;&的artifactId GT;的log4j&LT; / artifactId的&GT;
        &LT;&版GT; 1.2.14&LT; /版本&GT;
      &LT; /依赖性&GT;
    &LT; /依赖和GT;
  &LT; /插件&GT;

和这里就是我得到运行时编译MVN:

  [信息]扫描项目...
[INFO] ----------------------------------------------- -------------------------
[INFO]大厦聊天组件
[INFO]任务段:[编译]
[INFO] ----------------------------------------------- -------------------------
下载:HTTP://&LT;&删节GT; /content/groups/public/log4j/log4j/1.2.14/log4j-1.2.14.pom
2K下载
下载:HTTP://&LT;&删节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联系,并随机戳,直到它的工作,这里就是我得到了这个问题的工作,(我说的引号是因为它感觉很脆弱。)

下面是做它的方式正常工作:

 &LT;属性名=log4j_location
                值=$ {} maven.dependency.log4j.log4j.jar.path/&GT;
&LT;回声消息=$ {} log4j_location/&GT;

一些重要的事情需要注意:你的无法的使用Maven的依赖作为REFID在设置Ant属性。你必须使用$ {}来获取Maven的VAR值。

看来,依赖必须在顶级依赖关系列表,使得Log4j提供的antrun插件的依赖并不将其暴露在插件反正,我可以看到。

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

<块引用>

肥皂盒:

我会强烈建议任何人考虑的Maven使用Ant与Maven插件,或者甚至更好,使用Ant常春藤代替。

这特殊的问题是使用Maven做任何事情了规范的相关困难的荒谬绝伦水平的光辉典范。

我说这个已经实现了基于Maven2的整个构建系统,并具有蚂蚁还实施了几个版本的系统。我用两个的Maven2和Ant复杂的构建涉及Java时,Flex / AS3,C#和C ++。 Maven的有意​​义的的Java 的项目具有的没有的在其他语言的项目外部依赖性。

的Maven做处理一些事情,不被蚂蚁隐式处理,但也有一些预先的规划,蚂蚁是更加灵活,更好地记录和bug更少的工具。

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

我想你会最终会比使用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天全站免登陆