Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restructure for modularization. build with jdk11, target 8 #150

Merged
merged 5 commits into from
May 24, 2021

Conversation

pholser
Copy link
Collaborator

@pholser pholser commented May 10, 2021

No description provided.

Copy link
Contributor

@A248 A248 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could improve the build setup. I'm a little bit confused why you split the build into two maven modules, for the core and tests. My guess is that would only make testing in a modular setting more difficult. Did you run into issues trying to access test libraries?

<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there is already a JDK 11 build requirement, you can use the release option to ensure compatibility with Java 8. The --release flag can easily replace animal-sniffer and is very rock-solid.

For example:

<configuration>
    <release>8</release> <!-- Instead of source/target -->
</configuration>

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice -- thanks! Didn't grasp the release config.


<plugin>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The moditect plugin works, but I do not think it is the most bulletproof way to create a module descriptor. Moditect essentially has to duplicate all of the module-related logic in javac.

The maven-compiler-plugin supports compiling the descriptor as shown here: https://maven.apache.org/plugins/maven-compiler-plugin/examples/module-info.html . Just remove the toolchains from that example and it works fine - it compiles the main classes with the intended JDK compatibility and the module descriptor separately. While you can still make mistakes writing the module descriptor, just as you can with moditect, many of those mistakes will become compile-time errors.

Some similar discussion on the use of moditect versus other build architecture can be found here: java9-modularity/gradle-modules-plugin#72

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, great! I'll apply this learning to some of my other side projects also.

@pholser
Copy link
Collaborator Author

pholser commented May 11, 2021

I think you could improve the build setup. I'm a little bit confused why you split the build into two maven modules, for the core and tests. My guess is that would only make testing in a modular setting more difficult. Did you run into issues trying to access test libraries?

Nah, just figured I'd work toward having the tests know only about the exported stuff from the main module. Not quite there yet ... I'll implement your other suggestions first.

Thanks for the feedback! I'm learning a lot by undertaking this modularization.

@pholser
Copy link
Collaborator Author

pholser commented May 11, 2021

@A248 I appreciate the time you took to offer feedback on this PR.

Quick question: it's great that the maven-compiler-plugin can be made to compile a module-info.java file though we may be targeting JDK 8 for the bytecode. Should I be making a multi-release JAR, with the module-info tucked under META-INF/versions/9? Or is the blurb in the moditect docs about class file scanners choking on a module-info.class in a JAR such as mine overblown?

@A248
Copy link
Contributor

A248 commented May 11, 2021

I don't think a multi-release JAR is necessary. Creating a MRJAR adds a lot of build complexity with very little gain. They also do not play well with IDEs. On the other hand, they provide only marginal benefits for compatibility.

The same tools which distaste the module descriptor neither like MRJARs and will often fail on the module descriptor regardless of where it is placed. This is the case with old versions of Jetty and the Android Gradle Plugin. If you needed to target Android Studio and JDK 6 maybe a MRJAR would be a better choice, since those platforms will have incredibly ancient software. Much less so for JDK 8 users.

Also, sorry if I seem a little snappy, that's just how I sound some times. You sound a lot friendlier by comparison.

@pholser
Copy link
Collaborator Author

pholser commented May 13, 2021

@A248 Thanks again for your feedback. I've updated the configs and some tests in the process.

@pholser
Copy link
Collaborator Author

pholser commented May 15, 2021

Also, sorry if I seem a little snappy, that's just how I sound some times. You sound a lot friendlier by comparison.

@A248 No worries, I didn't get that sense at all. Appreciate the learning opportunities!

At your convenience, have a look at recent updates to this PR. I think we're converging on a satisfactory solution.

Copy link
Contributor

@A248 A248 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It all looks good to me. I'm sure you are aware the module name you chose is different from the previous Automatic-Module-Name, but that's fine since 6.0 is a new major release.

Also, you are dropping OSGI support, which I personally know little to nothing about.

@pholser
Copy link
Collaborator Author

pholser commented May 18, 2021

@A248 Thanks! re: OSGi -- you and me both. I suppose OSGi and JPMS metadata can coexist in a JAR, not sure how to get there just yet.

@pholser pholser merged commit 0e6a987 into master May 24, 2021
@pholser pholser deleted the issues/149/modularize branch May 24, 2021 04:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants