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

Where's the module-info.java file? #314

Closed
sormuras opened this issue Aug 6, 2020 · 8 comments
Closed

Where's the module-info.java file? #314

sormuras opened this issue Aug 6, 2020 · 8 comments

Comments

@sormuras
Copy link
Member

sormuras commented Aug 6, 2020

Add a module descriptor to the root of the JUnit Pioneer JAR file. Something like:

module org.junitpioneer {
  exports ...
  requires ...
}
@sormuras sormuras changed the title Where's the java-module.java file? Where's the module-info.java file? Aug 6, 2020
@Michael1993
Copy link
Member

Michael1993 commented Aug 6, 2020

JUnit Pioneer currently uses Java 8 (from the build.gradle.kts):

java {
	sourceCompatibility = JavaVersion.VERSION_1_8
}

Sadly, no module-info.java in Java 8. 😭

@Michael1993
Copy link
Member

Michael1993 commented Aug 6, 2020

What we can do:

  • Upgrade to Java 11
  • Create a new gradle profile with Java 11 and set up the Java 8 build to ignore the module-info.java

Optionally the source code can be updated to Java 11 (but only language elements, keeping same Java RT) and compiled back to Java 8 byte code with something like Jabel

@sormuras
Copy link
Member Author

sormuras commented Aug 6, 2020

Or use https://github.com/moditect/moditect

@nipafx
Copy link
Member

nipafx commented Aug 6, 2020

Still not convinced module declarations make too much sense for test code, but since it doesn't appear to hurt anyone (I infer from JUnit 5 having them for quite some time now), we can look into this.

Regarding the build, it appears easiest to me to make Java 11 the default/release build (with --release 8) and turn Java 8 into a "compatibility build" (like 14) where we exclude module-info.java.

@Bukama
Copy link
Member

Bukama commented Aug 8, 2020

When switching to modules I suggest to offer the PioneerTestKit and Assertions as an own module, so user can write their own extensions and use our Testkit / Assertions for it.

@nipafx
Copy link
Member

nipafx commented Aug 8, 2020

I did the simplest thing by adding a module-info.java and bump the source compatibility in Gradle:

diff --git a/build.gradle.kts b/build.gradle.kts
index f6cc08a..77fa80e 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -13,7 +13,7 @@ group = "org.junit-pioneer"
 description = "JUnit 5 Extension Pack"
 
 java {
-	sourceCompatibility = JavaVersion.VERSION_1_8
+	sourceCompatibility = JavaVersion.VERSION_11
 }
 
 repositories {
diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java
index 6b1b170..f0c6bce 100644
--- a/src/main/java/module-info.java
+++ b/src/main/java/module-info.java
@@ -1,2 +1,9 @@
-module $MODULE_NAME$ {
-}
\ No newline at end of file
+module org.junitpioneer {
+	// could be `transitive`, but that's its own discussion
+	requires org.junit.jupiter.api;
+	requires org.junit.jupiter.params;
+
+	exports org.junitpioneer.vintage;
+	exports org.junitpioneer.jupiter;
+	exports org.junitpioneer.jupiter.params;
+}

Result:

nipa 🤡 JUnit-Pioneer :: ./gradlew build

> Configure project :
  Building version '0.9.1' (value loaded from 'version.properties' file).

> Task :compileJava FAILED
/home/nipa/code/JUnit-Pioneer/src/main/java/module-info.java:3: error: module not found: org.junit.jupiter.api
        requires org.junit.jupiter.api;
                                  ^
/home/nipa/code/JUnit-Pioneer/src/main/java/module-info.java:4: error: module not found: org.junit.jupiter.params
        requires org.junit.jupiter.params;
                                  ^
2 errors

FAILURE: Build failed with an exception.

It seems to take more time and Hirnschmalz than I'm willing to spend on this task (because I'm still not convinced test modules are worth it). We welcome PRs on this, but we may not merge one without bumping the major version (talking post 1.0) and that may have to be a discussion on its own.

@Bukama
Copy link
Member

Bukama commented Aug 8, 2020

Gimme time, but I think I'm motivate to get in touch with the module-system myself for the first time.

@Bukama Bukama self-assigned this Aug 8, 2020
@sormuras
Copy link
Member Author

sormuras commented Aug 9, 2020

@Bukama This documentation could help: https://guides.gradle.org/building-java-9-modules/

As of Gradle 6.4, building Java Modules is supported by Gradle directly.

@nipafx nipafx closed this as completed in 3b67f16 Sep 26, 2020
Bukama pushed a commit that referenced this issue Oct 4, 2020
This commit cleans up the module build by removing two copy & paste
errors, where the full Git history was fetched (only needed for
Sonar, which is not used here) and the Gradle wrapper cache was
(still) disabled.

Related to: #314
PR: #350
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants