1

I am porting some Java 8 code to Java 11 with module-system.

One jar contains the following module:

module de.powerstat.fb.generator
 {
  exports de.powerstat.fb.generator;
  // ....
 }

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>

When now doing a

mvn clean install

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)
  ...

When commenting out now the following part:

<!--
<executableDependency>
  <groupId>de.powerstat.fb</groupId>
  <artifactId>generator</artifactId>
</executableDependency>
-->

Then the error changes to:

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)?

Just to let you know - I am using maven 3.6.3 on MacOS.

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

So it looks more like a problem of the plugin or maybe of maven itself.

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?

@Extension 2:

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]
PowerStat
  • 3,757
  • 8
  • 32
  • 57
  • the NPE is strange, is that the complete stack trace? could you identify which phase resulted in it? for the latter, I believe you can refer to a lot of threads talking over split packages in java modules. – Naman Feb 12 '21 at 17:08
  • 1
    No the NPE is not complete only the last important part. Split packages are not a problem - I know very well about them. The phase is generate-sources as you could see from the plugin configuration 8-) – PowerStat Feb 12 '21 at 19:51
  • @Naman looks like you are right with the split package problem within xerces and maven itself. – PowerStat Feb 13 '21 at 08:09

1 Answers1

0

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>
PowerStat
  • 3,757
  • 8
  • 32
  • 57