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

查看:37
本文介绍了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 来表示Storing",这会在存储内容的地方显示一堆日志输出.

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}"/>

需要注意的一些重要事项:不能在设置 ant 属性时使用 maven 依赖项作为 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++ 的复杂构建.Maven 适用于 Java 对其他语言的项目没有外部依赖的项目.

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.

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

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