[MJMOD-8] NullPointerException on create#2
[MJMOD-8] NullPointerException on create#2rfscholte merged 1 commit intoapache:masterfrom andretadeu:MJMOD-8
Conversation
|
First thanks for your contribution but on the other hand I'm thinking about this use case which looks to me like a different goal in the Plugin instead of having a complex parameter setup ? Can you give examples for use cases here? Complete example projects? |
|
Of course, I have two working examples: The first one I created a multi-module Maven project where I generated both JAR and JMOD files in each project that contains Java source code with module-info.java, which is in https://github.com/andretadeu/maven-jigsaw-examples/tree/master/multi-modules-jmod-jlink. The second project is the same project in the issue, but with fixes, where there is a separated project to generate the JMOD from JAR, which is in https://github.com/andretadeu/npe-on-alpha-2. Thinking about the approach of each module generating only one artifact, the second example seems more suitable, in my humble view. What do you think of these examples? |
|
Hi @khmarbaise , I am sorry! I forgot the integration test to explain how to reproduce the error correctly and to assert that the fix address this issue. Thanks, |
| <artifactId>maven-jmod-plugin</artifactId> | ||
| <extensions>true</extensions> | ||
| <configuration> | ||
| <classPath>${project.parent.basedir}/about-cli-app/target/about-cli-app-${project.version}.jar</classPath> |
There was a problem hiding this comment.
There should be no need for this classpath entry. about-cli-app is a dependency, so will be available as a pathElement.
There was a problem hiding this comment.
I think I made one mistake here: I should be filling pathElement. In JModCreateMojo:
else if ( classPath == null || classPath.trim().isEmpty() )
{
throw new MojoExecutionException( "You must either have a module in your project or the "
+ "'classPath' configuration set in 'maven-jmod-plugin' configuration section." );
}
I'll review this part and, in this case, I owe a better solution for this.
There was a problem hiding this comment.
I can replace this classPath entry with project.dependencyArtifacts. In the test case provided, pathElement is null because this Maven project just get a modular JAR and create a JMOD file from it. What ssems reasonable to do in this case is to fill classPath with project.dependencyArtifacts.
| } | ||
|
|
||
| if ( !pathElements.isEmpty() ) | ||
| if ( classPath != null && !classPath.trim().isEmpty() ) |
There was a problem hiding this comment.
You should be able to detect if there are classpath elements by looping over all the pathElements.
There was a problem hiding this comment.
Just one observation here: jmod create can receive both --module-path and --class-path. In this case, I think it is a better solution is to segregate JMOD artifacts and modular JARs from non-modular JARs. Fixing the previous explanation: --class-path must contain the artifact(s) or the folder(s) that should be inside JMOD file, i.e., you would expect that one modular JAR or target/classes folder would be enough. --module-path are the folders or files containing Java modules neede to compile. It's not clear how it should be used with jmod. In all examples I have, it is not used.
I am using Java 9 Modularity book and the official Oracle documentation for references.
|
@rfscholte Another proposal for this bug fix. |
|
The original code needs a clean up. It clearly shows to me that this was written while trying to understand the modular system based on code from other plugins. |
Done. I look forward to see the final solution. Thank you for all the help! |
|
Did you try to use the generated jmod? I would expect it to fail because it is missing picocli. IIUC |
|
I tested before of my refactoring and I didn't test it because I was expecting to maintain the behavior, since I was just replacing the origin of the information to fill classPath. I'll test again. However, I've discover another thing about --module-path (please check: https://github.com/java-modularity-examples/jigsaw-examples, example 10-exploring-jmod). We shouldn't be using --module-path, unless we want to setup a module that requires this module we are packing to add a hash on it, requiring the --hash-module parameter. |
I'll double check it. Check any number of times if needed. |
|
I tested now with Java 9, 10, and 11, and Maven 3.6.0: I ran the command: mvn clean verify -Prun-its, after that I removed the generated JMOD file, and executed the command: where the arguments were generated by maven-jmod-plugin and it's in jmodCreateArgs file. From the tests above, I didn't get the error you got. I confess I got this error, but it happened after I had made a mistake in my implementation. |
|
I've solved it in the refactor branch |
|
Concerning to the question of filling in the --class-path parameter, it looks good to me. |
|
It would be nice if you removed the commented out code. Thanks for everything. |
I'm also getting the above error. This happen when added different jars in my example project. |
|
Resolve #66 |
1 similar comment
|
Resolve #66 |
Hi,
I created this pull request to fulfill to address the need to set --class-path parameter from jmod create, because it offers the possibility to create a JMOD artifact from a JAR created in another project, in a Maven multi-module context.
Commit comment:
Thanks,
André Tadeu de Carvalho