ant - Maven Antrun和依赖项

标签 ant dependencies maven-2 maven-antrun-plugin

(请参见下面的编辑。)

我不能只使用类路径的原因是,因为我需要管理一些非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="My Dependency JAR-Path: ${mvn.dependency.jar}"/> 

无论如何尝试,我都无法完成这项工作。我已经尝试过将refid内容周围的$ {},我已经尝试了冒号,句点等。以我能想到的所有方式将其作为分隔符。

谁能告诉我这种常见的依赖关系应该是什么样的?

编辑:

感谢您的回复。

使用您的示例SingleShot,我有以下内容:
<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编译时得到的结果:
[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进行“存储”,这将显示一堆存储内容的日志输出。

有趣的事实是,我明确指定的依赖项未显示在列表中,并且当我基于我看到的条目之一切换到键时,仍然收到错误。

最佳答案

根据SingleShot链接到的代码并随机戳入,直到起作用为止,这就是我如何“正常工作”解决此问题的方式(我用引号表示,因为它感觉很脆弱)。

这是使其正常工作的方法:

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

需要注意的一些重要事项:在设置ant属性时,不能将maven依赖项用作引用。您必须使用$ {}来获取maven var值。

似乎该依赖项必须在顶级依赖项列表中,因此无论如何我都无法将log4j设置为antrun插件的依赖项不会将其公开给插件。

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

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.

关于ant - Maven Antrun和依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1580562/

相关文章:

java - Intellij 2019.1.3旗舰版无法安装maven依赖

version-control - Maven 2 项目版本、依赖版本和永久发布

java - 如何在我的 Java 项目中使用 Maven,为什么?

java - 必须在项目中设置 build.dir 错误

SVN-ANT 复制任务不起作用,来自 CLI 的 svn 复制可以,参数相同

java - Maven 停留在旧版本的系统依赖

visual-studio-2008 - 如何分发 C 运行时 (CRT) 库

jakarta-ee - 我需要帮助弄清楚为什么Ant会给我这个错误消息(设置Java Pet Store)?

java - 如何安装 Apache Ant?

apache-flex - 带有配置文件的条件 Maven 构建部分?