如何解决使用 antrun maven 插件从插件类路径中执行 jar
我有一个构建步骤,它使用 antrun 插件来执行代码生成器。代码生成器可作为 maven 插件使用,仅在构建步骤中需要。
我们将代码生成器依赖项作为应用程序的依赖项,并希望将其从打包中排除。我发现代码生成器不是应用程序的依赖项,因此它应该是插件的依赖项。
这曾经有效。
<dependencies>
<dependency>
<groupId>com.myCompany</groupId>
<artifactId>codeGenerator</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>codeGeneration</id>
<phase>initialize</phase>
<configuration>
<target>
<echo message="jar location: ${com.myCompany:codeGenerator:jar}"/>
<java jar="${com.myCompany:codeGenerator:jar}"
fork="true"
failonerror="true">
<arg value="--input"/>
<arg value=..."/>
</java>
</executions>
</plugin>
</plugins>
</build>
来自 maven 依赖项的 jar 被执行。 jar 文件解析成功。
[警告] [echo] jar 位置:/home/.../.m2/repository/com/mycompany/codegenerator/1.0/codegenerator.jar
我尝试将依赖项放入插件定义中并使用 maven.plugin.classpath 而不是 maven.dependency.classpath。
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>codeGeneration</id>
<phase>initialize</phase>
<configuration>
<target>
<property name="plugin_classpath" refid="maven.plugin.classpath"/>
<echo message="plugin classpath: ${plugin_classpath}"/>
<echo message="jar location: ${com.mycompany:codeGenerator:jar}"/>
<java jar="${com.myCompany:codeGenerator:jar}"
fork="true"
failonerror="true"
classpathref="maven.plugin.classpath">
<arg value="--input"/>
<arg value=".../>
</java>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.myCompany</groupId>
<artifactId>codeGenerator</artifactId>
<version></version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
类路径看起来不错,生成器已包含在内,但是一旦我从应用程序的依赖项中删除代码生成器,<java jar="${com.myCompany:codeGenerator:jar}
中的 jar 引用就不再起作用。
[警告] [echo] jar 位置:${com.myCompany:codeGenerator:jar} [INFO] [java] 错误:无法访问 jarfile /home/... /${com.myCompany:codeGenerator:jar}
为什么jar的分辨率停止工作?它是否以某种方式依赖于依赖类路径?有什么办法可以使它与插件类路径一起使用吗?
P.S.:我更喜欢在单独的 maven 模块中生成代码,但我想这只会移动问题而不是解决它。
<codegenerator-jar>
<!-- Workaround: normal jar resolution with ${groupId:artifactId:jar} only works if the dependency is in the dependency classpath. The code generator is only on the plugin classpath -->
${settings.localRepository}/com/mycompany/codegenerator/${sdk-version}/codegenerator-${sdk-version}.jar
</codegenerator-jar>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。