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

Java 9 support #23

Open
axelfontaine opened this issue Sep 2, 2017 · 7 comments
Open

Java 9 support #23

axelfontaine opened this issue Sep 2, 2017 · 7 comments

Comments

@axelfontaine
Copy link

As the GA release is due later this year...

@dbwiddis
Copy link
Contributor

dbwiddis commented Jun 1, 2020

This project is presently impossible to include in a Java 9+ project using JPMS. In order to include it, one has to enter a requires modluename in their module-info file.

This project has not configured any module name, so Java 9+ is falling back to an automatic method of determining the module name, which uses the jar file name, minus the version information. Hyphens are disallowed as characters in module names, so a dot is substituted, creating the automatic module name code.assert.

Unfortunately, assert is a reserved word in Java and thus not possible to include in a module name, so it is impossible to include code-assert as a required dependency. I am forced to either not use modules, or not use code-assert.

Providing module support to Java 9+ without implementing modules yourself is trivial if you use Maven as a build system. Simply add this to your parent pom.xml:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
      <archive>
        <manifestEntries>
          <Automatic-Module-Name>${autoModuleName}</Automatic-Module-Name>
        </manifestEntries>
      </archive>
    </configuration>
  </plugin>

And then in each of your modules, define that property, e.g., <autoModuleName>guru.nidi.codeassert<autoModuleName>

See this blog post for more details and reasoning why library maintainers should do this.

@dbwiddis
Copy link
Contributor

dbwiddis commented Jun 9, 2020

Any chance you can look into merging #40? Presently the lack of a legal module name is a blocker for using code-assert with JDK 9+.

@nidi3
Copy link
Owner

nidi3 commented Jul 13, 2020

Sorry for the long delay.
I merged your PR, thanks for it. There will be a release shortly.

@dbwiddis
Copy link
Contributor

Thanks! Before you release I hope you can test with mvn jar:jar and inspect the META-INF/MANIFEST.MF file to make sure the auto name got added. If not I might need to fix that configuration.

@nidi3
Copy link
Owner

nidi3 commented Jul 13, 2020

Yes, it's added.

@nidi3
Copy link
Owner

nidi3 commented Jul 14, 2020

released as 0.9.12

@dbwiddis
Copy link
Contributor

dbwiddis commented Feb 21, 2021

FYI, I have been struggling to include code-assert in a modular build. There are two unique issues:

  • There is a transitive dependency (via pmd) to javacc which is incompatible:
[ERROR] java.lang.module.FindException: Unable to derive module descriptor for /Users/danielwiddis/.m2/repository/net/java/dev/javacc/javacc/5.0/javacc-5.0.jar
[ERROR] Caused by: java.lang.module.InvalidModuleDescriptorException: jjdoc.class found in top-level directory (unnamed package not allowed in module)
  • There is a split package issue from hamcrest library modules.
[ERROR] java.lang.module.ResolutionException: Modules hamcrest.core and org.hamcrest export package org.hamcrest.internal to module junit

I was able to resolve that by changing my own dependency to the hamcrest-core artifact rather than hamcrest.

For the javacc error I've tried using exclusions to tweak things:

		<dependency>
			<groupId>guru.nidi</groupId>
			<artifactId>code-assert</artifactId>
			<version>${code-assert.version}</version>
			<scope>test</scope>
			<exclusions>
				<!-- pmd dependency has class in unnamed package -->
				<exclusion>
					<groupId>net.java.dev.javacc</groupId>
					<artifactId>javacc</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

but that now gives me a split package:

[ERROR] java.lang.module.ResolutionException: Modules pmd.java and pmd.core export package net.sourceforge.pmd.cpd to module saxon

I'm sure there's more I could do playing with exclusions here, but I'm getting out of my depth knowing all the code assert dependencies.

Not really a new problem or new solution but sharing progress in case anyone else is going down this road. I do think updating code assert to the latest version of most dependencies might clean a few things up.

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

No branches or pull requests

3 participants