datafaker icon indicating copy to clipboard operation
datafaker copied to clipboard

Problems with module-info.java with version 2.3.0

Open eitan-rosenberg opened this issue 1 year ago • 2 comments

After upgrade to version 2.3.0

I am getting: Error occurred during initialization of boot layer java.lang.module.FindException: Error reading module: G:\MyMavenRepo\net\datafaker\datafaker\2.3.0\datafaker-2.3.0.jar Caused by: java.lang.module.InvalidModuleDescriptorException: Package net.datafaker.formats not found in module

To solve the problem, I download the code.

I move datafaker-main\src\moditect\module-info.java to \src\main\java\module-info.java

After some modifications, I have a working jar.

Here is the modified module-info.java:

module net.datafaker {

	requires java.sql;
	requires java.management;
	requires java.desktop;

	requires org.yaml.snakeyaml;
	requires libphonenumber;
	requires rgxgen;

	exports net.datafaker;
	exports net.datafaker.annotations;
//	exports net.datafaker.formats;
	exports net.datafaker.idnumbers;
	exports net.datafaker.idnumbers.pt.br;
	exports net.datafaker.providers.base;
	exports net.datafaker.providers.entertainment;
	exports net.datafaker.providers.food;
	exports net.datafaker.providers.healthcare;
	exports net.datafaker.providers.sport;
	exports net.datafaker.providers.videogame;
	exports net.datafaker.sequence;
	exports net.datafaker.service;
	exports net.datafaker.service.files;
	exports net.datafaker.transformations;
	exports net.datafaker.transformations.sql;
//	exports net.datafaker.shaded.snakeyaml;

}

And here is the original module-info.java:

open module net.datafaker {
    requires java.sql;
    requires java.management;

    exports net.datafaker;
    exports net.datafaker.annotations;
    exports net.datafaker.formats;
    exports net.datafaker.idnumbers;
    exports net.datafaker.idnumbers.pt.br;
    exports net.datafaker.providers.base;
    exports net.datafaker.providers.entertainment;
    exports net.datafaker.providers.food;
    exports net.datafaker.providers.healthcare;
    exports net.datafaker.providers.sport;
    exports net.datafaker.providers.videogame;
    exports net.datafaker.sequence;
    exports net.datafaker.service;
    exports net.datafaker.service.files;
    exports net.datafaker.transformations;
    exports net.datafaker.transformations.sql;
    exports net.datafaker.shaded.snakeyaml;
}

Thanks.

eitan-rosenberg avatar Jul 01 '24 07:07 eitan-rosenberg

Hi @eitan-rosenberg , thanks for your report! Do you have a minimal example of how to reproduce this issue? We had a similar issue in the past, and I was under the impression it was fixed using the moditect-maven-plugin, but maybe I'm mistaken. But I known little of JPMS, and a sample would help a lot.

bodiam avatar Jul 01 '24 10:07 bodiam

IMHO, the problem is with the content of module-info.java (The original fail compile).
Try changing just this file (see the first post), I will be happy to test the resulting jar (Snapshot ?)

I am not familiar with moditect-maven-plugin. In my projects, I simply create module-info.java at the root of /src/main/java manually or let Eclipse do it for me.

To reproduce the problem, just follow https://www.datafaker.net/documentation/getting-started

I use maven.

<dependency>
    <groupId>net.datafaker</groupId>
    <artifactId>datafaker</artifactId>
    <version>2.3.0</version>
</dependency>

The project is using module-info.java

module moduleTest {

	requires net.datafaker;

}

This is what I get:

image

The code: ModuleTest.zip

eitan-rosenberg avatar Jul 01 '24 12:07 eitan-rosenberg

Thanks for sharing the moduleTest. I can see the error, I'm currently trying to understand what caused this regression.

bodiam avatar Jul 01 '24 22:07 bodiam

@bodiam I think we should NOT generate module-info.java automatically with any Maven plugins. The whole point of this file is to say explicitly what we want to expose.

I think we should manually create module-info.java in src/main/java and commit it (as @eitan-rosenberg suggested).

asolntsev avatar Jul 09 '24 07:07 asolntsev

I'm happy either way, I'm frankly unsure if that maven plugin even does anything? Happy to get rid of it and have a hardcoded file in the repo!

bodiam avatar Jul 09 '24 08:07 bodiam

@bodiam I think we should NOT generate module-info.java automatically with any Maven plugins. The whole point of this file is to say explicitly what we want to expose.

I think we should manually create module-info.java in src/main/java and commit it (as @eitan-rosenberg suggested).

This is the module-info.java that works for me:

module net.datafaker {

	requires java.sql;
	requires java.management;
	requires java.desktop;

	requires org.yaml.snakeyaml;
	requires libphonenumber;
	requires rgxgen;

	exports net.datafaker;
	exports net.datafaker.annotations;
//	exports net.datafaker.formats;
	exports net.datafaker.idnumbers;
	exports net.datafaker.idnumbers.pt.br;
	exports net.datafaker.providers.base;
	exports net.datafaker.providers.entertainment;
	exports net.datafaker.providers.food;
	exports net.datafaker.providers.healthcare;
	exports net.datafaker.providers.sport;
	exports net.datafaker.providers.videogame;
	exports net.datafaker.sequence;
	exports net.datafaker.service;
	exports net.datafaker.service.files;
	exports net.datafaker.transformations;
	exports net.datafaker.transformations.sql;
//	exports net.datafaker.shaded.snakeyaml;

}

eitan-rosenberg avatar Jul 09 '24 08:07 eitan-rosenberg

Should this do it? https://github.com/datafaker-net/datafaker/pull/1291

Update: seems it doesn't. Anyone tips?

bodiam avatar Jul 09 '24 10:07 bodiam

@eitan-rosenberg what is the error if you do not comment this line

exports net.datafaker.shaded.snakeyaml;

?

IIRC it was before and and should behave well

snuyanzin avatar Jul 09 '24 10:07 snuyanzin

@eitan-rosenberg what is the error if you do not comment this line

exports net.datafaker.shaded.snakeyaml;

?

IIRC it was before and and should behave well

+The package net.datafaker.shaded.snakeyaml does not exist or is empty

image

eitan-rosenberg avatar Jul 09 '24 11:07 eitan-rosenberg

I didn't get how you use this from one side you're saying that you use datafaker as a dependency from another side you're showing source code of datafaker

in source code of datafaker there is no such package and it is expected behavior however this package is generated while building datafaker for usage as a library to cope with dependency conflicts

snuyanzin avatar Jul 09 '24 12:07 snuyanzin

if same code worked for you with datafaker 2.2.x i'm think it should work for you with 2.3.x after this https://github.com/datafaker-net/datafaker/pull/1292

snuyanzin avatar Jul 09 '24 12:07 snuyanzin

I didn't get how you use this from one side you're saying that you use datafaker as a dependency from another side you're showing source code of datafaker

As I wrote, I download the source code of datafaker and I tinker with it. (Modifying module-info.java)

Then I install it to my local repository. I overwrite the original from maven central repository.

image

Then I created another project, as I wrote here : https://github.com/datafaker-net/datafaker/issues/1281#issuecomment-2200079816

With the modified module-info.java the project is working.

eitan-rosenberg avatar Jul 09 '24 13:07 eitan-rosenberg

if same code worked for you with datafaker 2.2.x i'm think it should work for you with 2.3.x after this #1292

Thanks.

How do I test it ?

eitan-rosenberg avatar Jul 09 '24 13:07 eitan-rosenberg

It seems our snapshots are broken due to a change at Sonatype. You could test it by doing a clone of the repo, do a local install, and depend on the snapshot version. If it works, I'll publish a release version.

bodiam avatar Jul 09 '24 14:07 bodiam

It seems our snapshots are broken due to a change at Sonatype. You could test it by doing a clone of the repo, do a local install, and depend on the snapshot version. If it works, I'll publish a release version.

Will do asap Thanks.

eitan-rosenberg avatar Jul 09 '24 14:07 eitan-rosenberg

In order to pass compile, I did the following:

  • Move module-info.java to src/main/java

  • Add requires java.desktop; requires org.yaml.snakeyaml; requires libphonenumber; requires rgxgen;

  • Comment out exports net.datafaker.shaded.snakeyaml;

open module net.datafaker {

	requires java.sql;
	requires java.management;

// Added
	requires java.desktop;
	requires org.yaml.snakeyaml;
	requires libphonenumber;
	requires rgxgen;

	exports net.datafaker;
	exports net.datafaker.annotations;
	exports net.datafaker.idnumbers;
	exports net.datafaker.idnumbers.pt.br;
	exports net.datafaker.providers.base;
	exports net.datafaker.providers.entertainment;
	exports net.datafaker.providers.food;
	exports net.datafaker.providers.healthcare;
	exports net.datafaker.providers.sport;
	exports net.datafaker.providers.videogame;
	exports net.datafaker.sequence;
	exports net.datafaker.service;
	exports net.datafaker.service.files;
	exports net.datafaker.transformations;
	exports net.datafaker.transformations.sql;

//	exports net.datafaker.shaded.snakeyaml;

}

eitan-rosenberg avatar Jul 09 '24 15:07 eitan-rosenberg

@eitan-rosenberg can you please check via this list of steps

  1. Go to some place where it is ok to place datafaker source and (if not done yet)
git clone [email protected]:datafaker-net/datafaker.git
  1. git checkout main && git reset --hard HEAD
  2. ./mvnw clean install -DskipTests
  3. go to your ModuleProject
  4. Replace dependency on datafaker with 2.3.1-SNAPSHOT
  5. try your test

snuyanzin avatar Jul 09 '24 22:07 snuyanzin

@eitan-rosenberg it would be great for us to know if the code works without these items:

	requires java.desktop;
	requires org.yaml.snakeyaml;
	requires libphonenumber;
	requires rgxgen;

We currently haven't added them to the snapshot version, so if you could try the steps at outlined by @snuyanzin , that would be great.

If it doesn't work, we'll add those extra lines, and publish another new version.

erikpragt-connectid avatar Jul 09 '24 23:07 erikpragt-connectid

@eitan-rosenberg it would be great for us to know if the code works without these items:

	requires java.desktop;
	requires org.yaml.snakeyaml;
	requires libphonenumber;
	requires rgxgen;

We currently haven't added them to the snapshot version, so if you could try the steps at outlined by @snuyanzin , that would be great.

If it doesn't work, we'll add those extra lines, and publish another new version.

No, it does not compile. I do not understand why in your case, your build does not fail. Maybe if you move module-info.java to \src\main\java\ you will see the errors.

I can see that this module stuff is a pain. You can use Automatic Module Name.

See: Automatic Module Name

There are quite a few libraries that use this option.

eitan-rosenberg avatar Jul 10 '24 06:07 eitan-rosenberg

@eitan-rosenberg can you please check via this list of steps

I do not use GitHub.

I simply download a zip and copy from it the necessary source.

For datafaker I copy \src\main\java and \src\main\resources (the yml files.)

The pom I use:


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

	<modelVersion>4.0.0</modelVersion>

	<groupId>net.datafaker</groupId>
	<artifactId>datafaker</artifactId>
	<version>2.3.0</version>

	<properties>
	
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<maven.compiler.source>${java.specification.version}</maven.compiler.source>
		<maven.compiler.target>${java.specification.version}</maven.compiler.target>

		<snakeyaml.version>2.2</snakeyaml.version>
		<rgxgen.version>2.0</rgxgen.version>
		<libphonenumber.version>8.13.40</libphonenumber.version>
		
	</properties>

	<dependencies>

		<dependency>
			<groupId>org.yaml</groupId>
			<artifactId>snakeyaml</artifactId>
			<version>${snakeyaml.version}</version>
		</dependency>
		<dependency>
			<groupId>com.github.curious-odd-man</groupId>
			<artifactId>rgxgen</artifactId>
			<version>${rgxgen.version}</version>
		</dependency>
		<dependency>
			<groupId>com.googlecode.libphonenumber</groupId>
			<artifactId>libphonenumber</artifactId>
			<version>${libphonenumber.version}</version>
		</dependency>

	</dependencies>

</project>

eitan-rosenberg avatar Jul 10 '24 06:07 eitan-rosenberg

Am I right that you extract datafaker's pom.xml, remove some not required for you lines and use it? Same probably for other files

snuyanzin avatar Jul 10 '24 06:07 snuyanzin

Am I right that you extract datafaker's pom.xml, remove some not required for you lines and use it? Same probably for other files

Yes. The pom contain just the dependencies. And I moved and modified module-info.java (Try first the original from https://github.com/datafaker-net/datafaker/blob/main/src/moditect/module-info.java)

image

eitan-rosenberg avatar Jul 10 '24 07:07 eitan-rosenberg

well, then that's the main problem

no one guarantees that it will work

for example in pom we have maven-shade-plugin which moves all the dependencies under net.datafaker.shaded package which doesn't exist in source code however will appear after execution of this step

and then we have modidect plugin which after everything is built (including net.datafaker.shaded package) builds module-info.java. That's the reason we have it in built jar and you don't since based on the pom you've shared you don't have this task with shading dependencies.

Moreover since the project is evolving it could happen that something else will appear in pom which will make such approach with files extraction / changes even more complex...

snuyanzin avatar Jul 10 '24 07:07 snuyanzin

@bodiam is it possible to create kind of beta release to simplify testing procedure for this issue in a way it was done here https://github.com/datafaker-net/datafaker/issues/1095#issuecomment-1975281199 ?

snuyanzin avatar Jul 10 '24 07:07 snuyanzin

@eitan-rosenberg Can you please test with this dependency (instead of datafaker)?

    <groupId>io.github.replay-framework</groupId>
    <artifactId>datafaker</artifactId>
    <version>2.3.1-SNAPSHOT</version>

This version contains the latest DF state in "main" branch.

P.S. Be sure you have added snapshots repository to your pom.xml:

<project>
  ...

  <repositories>
    <repository>
      <id>nexus</id>
      <name>nexus-snapshot</name>
      <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <releases>
        <enabled>false</enabled>
      </releases>
    </repository>
  </repositories>
</project>

asolntsev avatar Jul 10 '24 10:07 asolntsev

@eitan-rosenberg Can you please test with this dependency (instead of datafaker)?

I am Happy to say that we might have a winner !!!!

image

I do not understand how your module-info.java pass compile, but this is no important....

eitan-rosenberg avatar Jul 10 '24 11:07 eitan-rosenberg

@bodiam seems we should release 2.3.1 from current master branch.

asolntsev avatar Jul 10 '24 11:07 asolntsev

I'll release it.

bodiam avatar Jul 11 '24 12:07 bodiam

2.3.1 has been released!

bodiam avatar Jul 11 '24 13:07 bodiam

Good morning.

Thank you all, it is working just fine.

Have a nice weekend.

eitan-rosenberg avatar Jul 12 '24 06:07 eitan-rosenberg