问题描述
我有一个构建步骤,它使用 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 (将#修改为@)