[英]How to fix exec-maven-plugin with plugin dependencies and java module-system?
我正在使用模塊系統將一些 Java 8 代碼移植到 Java 11 中。
一個 jar 包含以下模塊:
module de.powerstat.fb.generator
{
exports de.powerstat.fb.generator;
// ....
}
這是完美的工作。 現在在另一個 maven 項目中,我在 pom 中引用這個 jar/模塊:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<includeProjectDependencies>false</includeProjectDependencies>
<includePluginDependencies>true</includePluginDependencies>
<executableDependency>
<groupId>de.powerstat.fb</groupId>
<artifactId>generator</artifactId>
</executableDependency>
<mainClass>de.powerstat.fb.generator/de.powerstat.fb.generator.CodeGenerator</mainClass>
<arguments>
<argument>${fb.hostname}</argument>
<argument>${fb.port}</argument>
<argument>${fb.username}</argument>
<argument>${fb.password}</argument>
<argument>${project.build.directory}</argument>
</arguments>
<cleanupDaemonThreads>false</cleanupDaemonThreads>
</configuration>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>de.powerstat.fb</groupId>
<artifactId>generator</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
當現在做一個
mvn clean install
這會導致 NullPointerException:
...
Caused by: java.lang.NullPointerException
at org.codehaus.mojo.exec.AbstractExecMojo.findExecutableArtifact (AbstractExecMojo.java:277)
at org.codehaus.mojo.exec.ExecJavaMojo.determineRelevantPluginDependencies (ExecJavaMojo.java:606)
at org.codehaus.mojo.exec.ExecJavaMojo.addRelevantPluginDependenciesToClasspath (ExecJavaMojo.java:539)
at org.codehaus.mojo.exec.ExecJavaMojo.getClassLoader (ExecJavaMojo.java:492)
at org.codehaus.mojo.exec.ExecJavaMojo.execute (ExecJavaMojo.java:273)
...
現在注釋掉以下部分時:
<!--
<executableDependency>
<groupId>de.powerstat.fb</groupId>
<artifactId>generator</artifactId>
</executableDependency>
-->
然后錯誤變為:
Caused by: java.lang.module.ResolutionException: Modules xml.apis and xercesImpl export package org.w3c.dom.html to module maven.model
at java.lang.module.Resolver.resolveFail (Resolver.java:885)
at java.lang.module.Resolver.failTwoSuppliers (Resolver.java:797)
at java.lang.module.Resolver.checkExportSuppliers (Resolver.java:718)
at java.lang.module.Resolver.finish (Resolver.java:362)
at java.lang.module.Configuration.<init> (Configuration.java:141)
at java.lang.module.Configuration.resolve (Configuration.java:424)
at java.lang.module.Configuration.resolve (Configuration.java:256)
at org.codehaus.mojo.exec.LoaderFinder.find (LoaderFinder.java:54)
at org.codehaus.mojo.exec.ExecJavaMojo.getClassLoader (ExecJavaMojo.java:498)
at org.codehaus.mojo.exec.ExecJavaMojo.execute (ExecJavaMojo.java:273)
所以我的問題是,我能做些什么來解決這種情況? 也許我做錯了什么? 或者它是插件中的一個錯誤? 如果它是插件中的錯誤 - 是否有某種解決方法(因為插件看起來沒有維護)?
只是讓您知道 - 我在 MacOS 上使用 maven 3.6.3。
@分機1:
今天在使用上面注釋掉的代碼進行編譯時,我收到了一條不同的錯誤消息:
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.0.0:java (default) on project gentr64: Execution default of goal org.codehaus.mojo:exec-maven-plugin:3.0.0:java failed: Module sisu.inject.bean contains package org.sonatype.guice.asm, module sisu.inject.plexus exports package org.sonatype.guice.asm to sisu.inject.bean -> [Help 1]
所以它看起來更像是插件的問題,或者可能是 maven 本身的問題。
我想問題可能是我試圖在一個模塊內執行 java class 並且因為 maven 沒有模塊化,這會失敗嗎? 也許有人可以證實或偽造這個理論?
@擴展 2:
從我的 pom 中刪除 jacoco 插件后,我得到了另一個不同的錯誤:
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.0.0:java (default) on project gentr64: Execution default of goal org.codehaus.mojo:exec-maven-plugin:3.0.0:java failed: Module maven.core contains package org.apache.maven.plugin, module maven.plugin.api exports package org.apache.maven.plugin to maven.core -> [Help 1]
最后,在模塊化 Z68995FCBF432492D15484D04A9 上嘗試使用 exec:java 時,看起來 maven 3.6.3 和 exec-maven-plugin 無法正常工作。
作為解決方法/解決方案,我使用了以下內容:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<id>copy</id>
<phase>initialize</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>de.powerstat.fb</groupId>
<artifactId>generator</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>target</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<executable>java</executable>
<arguments>
<argument>-jar</argument>
<argument>target/generator-1.0-SNAPSHOT.jar</argument>
<argument>${fb.hostname}</argument>
<argument>${fb.port}</argument>
<argument>${fb.username}</argument>
<argument>${fb.password}</argument>
<argument>${project.build.directory}</argument>
</arguments>
</configuration>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.