如何使用插件依赖项和Java模块系统修复exec-maven-plugin? [英] How to fix exec-maven-plugin with plugin dependencies and java module-system?
问题描述
我正在使用模块系统将一些Java 8代码移植到Java 11.
I am porting some Java 8 code to Java 11 with module-system.
一个jar包含以下模块:
One jar contains the following module:
module de.powerstat.fb.generator
{
exports de.powerstat.fb.generator;
// ....
}
这是完美的工作.现在在另一个Maven项目中,我在pom中引用了这个jar/模块:
which is perfectly working. Now within another maven project I am referencing this jar/module within the pom:
<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:
this results in a 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)
所以我的问题是,我该怎么做才能解决这种情况?也许我做错了什么?还是插件中的错误?如果它是插件中的错误-是否有某种解决方法(因为该插件看起来无法维护)?
So my question is, what could I do to fix this situation? Maybe I am doing something wrong? Or is it a bug in the plugin? If it is a bug within the plugin - is there some kind of workaround (because the plugin looks unmaintained)?
只是让您知道-我在MacOS上使用的是maven 3.6.3.
Just to let you know - I am using maven 3.6.3 on MacOS.
@ Extension1:
@Extension1:
今天,使用上面注释掉的代码进行编译时,我得到了另一条错误消息:
Today when compiling with the above commented out code I got a different error message:
[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本身的问题.
So it looks more like a problem of the plugin or maybe of maven itself.
我想问题可能是我试图在模块内执行Java类,并且由于未对Maven进行模块化,这会失败吗?也许有人可以证实或伪造这一理论?
I guess that the problem might be that I am trying to execute a java class within a module and because maven is not modularized this fails? Maybe someone could confirm or falsify this theroy?
@扩展程序2:
从pom删除jacoco插件后,我又遇到了另一个错误:
After removing the jacoco plugin from my pom, I got another different error:
[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似乎无法正常工作.
At the end it looks like maven 3.6.3 and the exec-maven-plugin are not working correctly when trying to use exec:java on a modularized jar.
作为解决方法/解决方案,我使用了以下方法:
As a workaround/solution to this I used the following:
<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>
这篇关于如何使用插件依赖项和Java模块系统修复exec-maven-plugin?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!