4

While moving a project to Gradle, I stopped using my custom build of org.json which had a module-info.java fitted to it to comply to the module system. Now, I am using it via Maven normally, and as org.json is not a module by default, it gets put into the unnamed module.

My module-info looks like this:

open module mymodule { requires java.desktop; requires java.logging; } 

I am getting the error:

SomeSourceFile.java: error: package org.json is not visible import org.json.*; ^ (package org.json is declared in the unnamed module, but module mymodule does not read it) 

This is logical, except I don't know why my module doesn't read the unnamed module (the purpose of the unnamed module is full backwards compatibility with non-modular software so all packages are exported etc.), and how I could make my module read the unnamed module. As you can see, I have already tried making my module open to no avail.

1
  • You have to put the org.json jar on the module path - if it doesn't have a module descriptor, it will be an automatic module, which you can require. Commented Mar 20, 2021 at 2:14

1 Answer 1

1

Probably updating the Maven Compiler Plugin (to 3.8.1, for instance) will do the trick.

<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> </plugin> </plugins> </build> 

The other thing will be to require the JSON module. From their pom.xml, I can see that they declare the Automatic-Module-Name as org.json (https://github.com/stleary/JSON-java/blob/master/pom.xml#L186)

So your module-info.java will become like this:

open module mymodule { requires java.desktop; requires java.logging; requires org.json; } 
Sign up to request clarification or add additional context in comments.

3 Comments

This is not a maven project, it is a gradle project using the maven repository for packages. But it does seem like maven is the only build system that can handle this conflict at the present time.
I don't have enough Gradle experience to help then, but this link might help
Well, this is one of the doc pages I have read several times over and it doesn't help.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.