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

Add Java 8 support #28

Closed
wants to merge 2 commits into from
Closed

Add Java 8 support #28

wants to merge 2 commits into from

Conversation

Glavo
Copy link
Contributor

@Glavo Glavo commented Jan 6, 2023

By setting the mixedJavaRelease, we can easily provide module-info.class while supporting Java 8.

Many users are still using Java 8. We have a popular JavaFX application that has to remain compatible with Java 8, and it depends on fx-gson. Providing support for Java 8 allows us to upgrade fx gson from 3. x to 4. x, so we hope you can merge this PR.

@Glavo Glavo force-pushed the main branch 2 times, most recently from ea3f4ff to e780bbc Compare January 6, 2023 23:13
build.gradle.kts Outdated
Comment on lines 24 to 26
tasks.getByName<Jar>("sourcesJar") {
exclude("module-info.class")
}
Copy link
Owner

@joffrey-bion joffrey-bion Jan 7, 2023

Choose a reason for hiding this comment

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

Why would this class file be part of the sources jar in the first place? Could you please elaborate on why you had to add this exclusion? (also if there is a good reason please add it as a comment in the code)

Copy link
Contributor Author

@Glavo Glavo Jan 7, 2023

Choose a reason for hiding this comment

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

Why would this class file be part of the sources jar in the first place? Could you please elaborate on why you had to add this exclusion? (also if there is a good reason please add it as a comment in the code)

After setting the mixedJavaRelease, the module-info.class will also be packaged into the sourcesJar. I think this may be a bug with the gradle-modules-plugin.

Copy link
Owner

Choose a reason for hiding this comment

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

Ok thank you. It might be worth reporting this to the plugin authors then. Do you have a link to an issue?

Copy link
Owner

Choose a reason for hiding this comment

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

It looks like there is a similar problem with the Javadoc jar too, by the way

Copy link
Owner

Choose a reason for hiding this comment

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

I fixed that in my branch and opened this issue: java9-modularity/gradle-modules-plugin#220

Comment on lines +30 to +34
tasks.compileTestJava {
extensions.configure<org.javamodularity.moduleplugin.extensions.CompileTestModuleOptions> {
isCompileOnClasspath = true
}
}
Copy link
Owner

Choose a reason for hiding this comment

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

Why did we need to fallback to classpath mode? Does that mean that consumers of the library will have to use the classpath instead of the module path as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why did we need to fallback to classpath mode? Does that mean that consumers of the library will have to use the classpath instead of the module path as well?

This is only for testing, and will not affect the release.

Some module related problems prevent the test, and this option can make the test work normally.

Copy link
Owner

@joffrey-bion joffrey-bion Jan 7, 2023

Choose a reason for hiding this comment

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

This is only for testing, and will not affect the release

This specific setting is only for testing, yes. But the fact that you had to do this makes me wary because it might be a symptom of a problem that does affect the release.

Some module related problems prevent the test

Exactly. What is it? Is this problem going to affect consumers? That's exactly my question.

this option can make the test work normally

Yes, but it seems it's just hiding the problem with the modules (unless we understand what the problem is more clearly).

Copy link
Contributor Author

@Glavo Glavo Jan 7, 2023

Choose a reason for hiding this comment

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

@joffrey-bion In fact, Gradle's test could not correctly reflect the module related problems.

Testing is completely different from users. The user uses the last generated jar file, and the test is based on the class files in the folder.

Moreover, the test itself in this project has broken the module assumption —— Jigsaw does not allow different modules to contain the same package, so your tests can work normally only after they have invaded the module.

The Jigsaw problem encountered here should be caused by a bug in the gradle modules plugin. This plugin has many bugs. If the JavaFX Gradle Plugin plugin does not depends on it, I do not want to use it.

However, based on my experience working on dozens of modular Java projects, I think it is reasonable to use classpath directly. Because I haven't seen any build tool that can correctly handle Jigsaw in all cases, Gradle itself also has many module related bugs, it is difficult to avoid using workaround in projects to bypass problems related to jigsaw.

Compiling tests using the classpath does not cause any more problems. This is how Gradle works by default. I'm just asking the gradle module plugin to use the default behavior of gradle, so that the plugin will not cause us trouble because of its own bugs.

Copy link
Owner

Choose a reason for hiding this comment

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

In fact, Gradle's test could not correctly reflect the module related problems.

It did for me in the past. Before your change, my tests had shown me I was lacking opens declarations for Gson for example.

The user uses the last generated jar file, and the test is based on the class files in the folder.

By default, yes, but I think that depends on how tests are setup. I think with the Gradle Modules Plugin this default changes, because it sets up Gradle to use the module path instead. That's probably why my tests could catch problems with modules so far.

However, based on my experience working on dozens of modular Java projects, I think it is reasonable to use classpath directly

I am not convinced that it is reasonable. A good quality library should ideally test both when the jar is used on the module path AND on the classpath.

Copy link
Owner

Choose a reason for hiding this comment

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

For some reason, despite the classpath mode it seems to pickup the problems in module-info.java, so it might be good enough for now 🤔

@Glavo
Copy link
Contributor Author

Glavo commented Jan 8, 2023

I think it is more convenient for me to maintain a fork that supports Java 8.

@joffrey-bion
Copy link
Owner

joffrey-bion commented Jan 8, 2023

I think it is more convenient for me to maintain a fork that supports Java 8.

Why is that? I'm actually working on Java 8 support right now based on your PR. Just because I'm not merging immediately without good enough reasons for each piece you added doesn't mean I'm not willing to add support.

I'm genuinely trying to find the best way to do so. Not yolo something that work-ish without proper testing.

@Glavo
Copy link
Contributor Author

Glavo commented Jan 8, 2023

Because I don't want to continue to spend too much time on Jigsaw, which will make me very depressed.

In the past few years, I have spent a lot of time to solve these problems. I have tried gradle modules plugin, but it is not a good solution. It has too many bugs.

For Jigsaw, I finally implemented a compiler dedicated to module-info. java to bypass these troubles by not doing any checks.

It is worth mentioning that a widely used plugin (ModiTect ) of Maven works in the same way. Many projects, including jackson, have added module-info.class in this way.

@Glavo
Copy link
Contributor Author

Glavo commented Jan 8, 2023

It seems that you have added Java 8 support? I'm glad to see you accept these concessions.

@joffrey-bion
Copy link
Owner

Because I don't want to continue to spend too much time on Jigsaw, which will make me very depressed. In the past few years, I have spent a lot of time to solve these problems. I have tried gradle modules plugin, but it is not a good solution. It has too many bugs.

I understand your pain. I'm mostly working in Kotlin these days, so I have almost 0 contact with JPMS apart from this library.

It seems that you have added Java 8 support?

What I'm trying to achieve here is to provide reasonable support for the majority of people. And given the numbers in the survey Java 8 is still quite prevalent despite being old. And I think if we could have JavaFX-specific numbers, the value might be much higher than 45% marketshare. This is why I'm willing to revisit my former decision of "just move on in v4, and users that want to use JRE 8 can use FX Gson v3". I think it's best if new features / bugfixes in this lib benefit all users.

I'm glad to see you accept these concessions

As I mentioned in a comment above, I just tested with the classpath mode and it seems to still pick up issues with module-info.java. This was my main blocker. So this is good enough for me at the moment.

@joffrey-bion
Copy link
Owner

Released in FX Gson 5.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants