如何修复execen -plugin与插件依赖关系和java模块系统?



我正在用模块系统将一些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)

所以我的问题是,我能做些什么来解决这种情况?也许我做错了什么?或者是插件的bug ?如果是插件内部的bug -是否有某种解决方法(因为插件看起来没有维护)?

只是让你知道-我在MacOS上使用maven 3.6.3。

@Extension1:

今天,当用上面注释掉的代码编译时,我得到了一个不同的错误信息:

[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类,因为maven不是模块化的,这失败了吗?也许有人能证实或证伪这个理论?

@Extension 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]

最后,当试图在模块化的jar上使用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>

最新更新