From 91468c0852324a7d01e0ee4701de99e690abede6 Mon Sep 17 00:00:00 2001 From: Jendrik Johannes Date: Fri, 30 Jun 2023 13:14:19 +0200 Subject: [PATCH] Add 'Module Info DSL' examples --- .../app/build.gradle.kts | 24 +++++++++++ .../app/src/main/java/module-info.java | 6 +++ .../src/main/java/org/example/app/App.java | 16 ++++++++ .../test/java/org/example/app/AppTest.java | 26 ++++++++++++ .../app/src/test/resources/data.txt | 1 + .../src/testFunctional/java/module-info.java | 4 ++ .../example/app/test/AppFunctionalTest.java | 25 +++++++++++ .../app/src/testFunctional/resources/data.txt | 1 + .../build.gradle.kts | 3 ++ samples/module-info-dsl-no-platform/build.out | 38 +++++++++++++++++ .../build.sample.conf | 2 + .../gradle/plugins/build.gradle.kts | 9 ++++ .../gradle/plugins/settings.gradle.kts | 6 +++ .../kotlin/org.example.java-base.gradle.kts | 19 +++++++++ .../org.example.java-module-app.gradle.kts | 5 +++ .../kotlin/org.example.java-module.gradle.kts | 5 +++ .../main/kotlin/org.example.root.gradle.kts | 3 ++ .../lib/build.gradle.kts | 7 ++++ .../lib/src/main/java/module-info.java | 7 ++++ .../src/main/java/org/example/lib/Lib.java | 10 +++++ .../test/java/org/example/lib/LibTest.java | 23 +++++++++++ .../lib/src/test/resources/data.txt | 1 + .../src/testFunctional/java/module-info.java | 4 ++ .../example/lib/test/LibFunctionalTest.java | 24 +++++++++++ .../lib/src/testFunctional/resources/data.txt | 1 + .../settings.gradle.kts | 8 ++++ samples/module-info-dsl/app/build.gradle.kts | 17 ++++++++ .../app/src/main/java/module-info.java | 6 +++ .../src/main/java/org/example/app/App.java | 16 ++++++++ .../test/java/org/example/app/AppTest.java | 26 ++++++++++++ .../app/src/test/resources/data.txt | 1 + .../src/testFunctional/java/module-info.java | 4 ++ .../example/app/test/AppFunctionalTest.java | 25 +++++++++++ .../app/src/testFunctional/resources/data.txt | 1 + samples/module-info-dsl/build.gradle.kts | 3 ++ samples/module-info-dsl/build.out | 41 +++++++++++++++++++ samples/module-info-dsl/build.sample.conf | 2 + .../gradle/plugins/build.gradle.kts | 9 ++++ .../gradle/plugins/settings.gradle.kts | 6 +++ .../kotlin/org.example.java-base.gradle.kts | 19 +++++++++ .../org.example.java-module-app.gradle.kts | 4 ++ ...rg.example.java-module-versions.gradle.kts | 4 ++ .../kotlin/org.example.java-module.gradle.kts | 5 +++ .../main/kotlin/org.example.root.gradle.kts | 3 ++ samples/module-info-dsl/lib/build.gradle.kts | 9 ++++ .../lib/src/main/java/module-info.java | 7 ++++ .../src/main/java/org/example/lib/Lib.java | 10 +++++ .../test/java/org/example/lib/LibTest.java | 23 +++++++++++ .../lib/src/test/resources/data.txt | 1 + .../src/testFunctional/java/module-info.java | 4 ++ .../example/lib/test/LibFunctionalTest.java | 24 +++++++++++ .../lib/src/testFunctional/resources/data.txt | 1 + samples/module-info-dsl/settings.gradle.kts | 9 ++++ .../module-info-dsl/versions/build.gradle.kts | 10 +++++ 54 files changed, 568 insertions(+) create mode 100644 samples/module-info-dsl-no-platform/app/build.gradle.kts create mode 100644 samples/module-info-dsl-no-platform/app/src/main/java/module-info.java create mode 100644 samples/module-info-dsl-no-platform/app/src/main/java/org/example/app/App.java create mode 100644 samples/module-info-dsl-no-platform/app/src/test/java/org/example/app/AppTest.java create mode 100644 samples/module-info-dsl-no-platform/app/src/test/resources/data.txt create mode 100644 samples/module-info-dsl-no-platform/app/src/testFunctional/java/module-info.java create mode 100644 samples/module-info-dsl-no-platform/app/src/testFunctional/java/org/example/app/test/AppFunctionalTest.java create mode 100644 samples/module-info-dsl-no-platform/app/src/testFunctional/resources/data.txt create mode 100644 samples/module-info-dsl-no-platform/build.gradle.kts create mode 100644 samples/module-info-dsl-no-platform/build.out create mode 100644 samples/module-info-dsl-no-platform/build.sample.conf create mode 100644 samples/module-info-dsl-no-platform/gradle/plugins/build.gradle.kts create mode 100644 samples/module-info-dsl-no-platform/gradle/plugins/settings.gradle.kts create mode 100644 samples/module-info-dsl-no-platform/gradle/plugins/src/main/kotlin/org.example.java-base.gradle.kts create mode 100644 samples/module-info-dsl-no-platform/gradle/plugins/src/main/kotlin/org.example.java-module-app.gradle.kts create mode 100644 samples/module-info-dsl-no-platform/gradle/plugins/src/main/kotlin/org.example.java-module.gradle.kts create mode 100644 samples/module-info-dsl-no-platform/gradle/plugins/src/main/kotlin/org.example.root.gradle.kts create mode 100644 samples/module-info-dsl-no-platform/lib/build.gradle.kts create mode 100644 samples/module-info-dsl-no-platform/lib/src/main/java/module-info.java create mode 100644 samples/module-info-dsl-no-platform/lib/src/main/java/org/example/lib/Lib.java create mode 100644 samples/module-info-dsl-no-platform/lib/src/test/java/org/example/lib/LibTest.java create mode 100644 samples/module-info-dsl-no-platform/lib/src/test/resources/data.txt create mode 100644 samples/module-info-dsl-no-platform/lib/src/testFunctional/java/module-info.java create mode 100644 samples/module-info-dsl-no-platform/lib/src/testFunctional/java/org/example/lib/test/LibFunctionalTest.java create mode 100644 samples/module-info-dsl-no-platform/lib/src/testFunctional/resources/data.txt create mode 100644 samples/module-info-dsl-no-platform/settings.gradle.kts create mode 100644 samples/module-info-dsl/app/build.gradle.kts create mode 100644 samples/module-info-dsl/app/src/main/java/module-info.java create mode 100644 samples/module-info-dsl/app/src/main/java/org/example/app/App.java create mode 100644 samples/module-info-dsl/app/src/test/java/org/example/app/AppTest.java create mode 100644 samples/module-info-dsl/app/src/test/resources/data.txt create mode 100644 samples/module-info-dsl/app/src/testFunctional/java/module-info.java create mode 100644 samples/module-info-dsl/app/src/testFunctional/java/org/example/app/test/AppFunctionalTest.java create mode 100644 samples/module-info-dsl/app/src/testFunctional/resources/data.txt create mode 100644 samples/module-info-dsl/build.gradle.kts create mode 100644 samples/module-info-dsl/build.out create mode 100644 samples/module-info-dsl/build.sample.conf create mode 100644 samples/module-info-dsl/gradle/plugins/build.gradle.kts create mode 100644 samples/module-info-dsl/gradle/plugins/settings.gradle.kts create mode 100644 samples/module-info-dsl/gradle/plugins/src/main/kotlin/org.example.java-base.gradle.kts create mode 100644 samples/module-info-dsl/gradle/plugins/src/main/kotlin/org.example.java-module-app.gradle.kts create mode 100644 samples/module-info-dsl/gradle/plugins/src/main/kotlin/org.example.java-module-versions.gradle.kts create mode 100644 samples/module-info-dsl/gradle/plugins/src/main/kotlin/org.example.java-module.gradle.kts create mode 100644 samples/module-info-dsl/gradle/plugins/src/main/kotlin/org.example.root.gradle.kts create mode 100644 samples/module-info-dsl/lib/build.gradle.kts create mode 100644 samples/module-info-dsl/lib/src/main/java/module-info.java create mode 100644 samples/module-info-dsl/lib/src/main/java/org/example/lib/Lib.java create mode 100644 samples/module-info-dsl/lib/src/test/java/org/example/lib/LibTest.java create mode 100644 samples/module-info-dsl/lib/src/test/resources/data.txt create mode 100644 samples/module-info-dsl/lib/src/testFunctional/java/module-info.java create mode 100644 samples/module-info-dsl/lib/src/testFunctional/java/org/example/lib/test/LibFunctionalTest.java create mode 100644 samples/module-info-dsl/lib/src/testFunctional/resources/data.txt create mode 100644 samples/module-info-dsl/settings.gradle.kts create mode 100644 samples/module-info-dsl/versions/build.gradle.kts diff --git a/samples/module-info-dsl-no-platform/app/build.gradle.kts b/samples/module-info-dsl-no-platform/app/build.gradle.kts new file mode 100644 index 0000000..66df152 --- /dev/null +++ b/samples/module-info-dsl-no-platform/app/build.gradle.kts @@ -0,0 +1,24 @@ +plugins { + id("org.example.java-module-app") +} + +application { + applicationDefaultJvmArgs = listOf("-ea") + mainClass.set("org.example.app.App") + mainModule.set("org.example.app") +} + +mainModuleInfo { + runtimeOnly("org.slf4j.simple") +} + +testModuleInfo { + requires("org.junit.jupiter.api") +} + +moduleInfo { + version("org.slf4j", "2.0.7") + version("org.slf4j.simple", "2.0.7") + version("com.fasterxml.jackson.databind", "2.14.0") + version("org.junit.jupiter.api", "5.9.3") +} diff --git a/samples/module-info-dsl-no-platform/app/src/main/java/module-info.java b/samples/module-info-dsl-no-platform/app/src/main/java/module-info.java new file mode 100644 index 0000000..cc02079 --- /dev/null +++ b/samples/module-info-dsl-no-platform/app/src/main/java/module-info.java @@ -0,0 +1,6 @@ +module org.example.app { + requires org.example.lib; + requires org.slf4j; + + exports org.example.app; +} \ No newline at end of file diff --git a/samples/module-info-dsl-no-platform/app/src/main/java/org/example/app/App.java b/samples/module-info-dsl-no-platform/app/src/main/java/org/example/app/App.java new file mode 100644 index 0000000..deb09b1 --- /dev/null +++ b/samples/module-info-dsl-no-platform/app/src/main/java/org/example/app/App.java @@ -0,0 +1,16 @@ +package org.example.app; + +import org.example.lib.Lib; +import org.slf4j.LoggerFactory; + +public class App { + + public static void main(String[] args) { + LoggerFactory.getLogger(App.class).info("App running..."); + doWork(); + } + + public static void doWork() { + new Lib(); + } +} \ No newline at end of file diff --git a/samples/module-info-dsl-no-platform/app/src/test/java/org/example/app/AppTest.java b/samples/module-info-dsl-no-platform/app/src/test/java/org/example/app/AppTest.java new file mode 100644 index 0000000..c50a6ee --- /dev/null +++ b/samples/module-info-dsl-no-platform/app/src/test/java/org/example/app/AppTest.java @@ -0,0 +1,26 @@ +package org.example.app; + +import org.example.lib.Lib; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.io.InputStream; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class AppTest { + + @Test + public void testApp() throws IOException { + assertEquals("org.example.lib", Lib.class.getModule().getName()); + assertEquals("org.example.app", App.class.getModule().getName()); + assertEquals("org.example.app", AppTest.class.getModule().getName()); + try (InputStream is = AppTest.class.getResourceAsStream("/data.txt")) { + assertNotNull(is); + assertEquals("ABC", new String(is.readAllBytes(), UTF_8)); + } + } + +} \ No newline at end of file diff --git a/samples/module-info-dsl-no-platform/app/src/test/resources/data.txt b/samples/module-info-dsl-no-platform/app/src/test/resources/data.txt new file mode 100644 index 0000000..48b83b8 --- /dev/null +++ b/samples/module-info-dsl-no-platform/app/src/test/resources/data.txt @@ -0,0 +1 @@ +ABC \ No newline at end of file diff --git a/samples/module-info-dsl-no-platform/app/src/testFunctional/java/module-info.java b/samples/module-info-dsl-no-platform/app/src/testFunctional/java/module-info.java new file mode 100644 index 0000000..f54dadf --- /dev/null +++ b/samples/module-info-dsl-no-platform/app/src/testFunctional/java/module-info.java @@ -0,0 +1,4 @@ +open module org.example.app.test.functional { + requires org.example.app; + requires org.junit.jupiter.api; +} \ No newline at end of file diff --git a/samples/module-info-dsl-no-platform/app/src/testFunctional/java/org/example/app/test/AppFunctionalTest.java b/samples/module-info-dsl-no-platform/app/src/testFunctional/java/org/example/app/test/AppFunctionalTest.java new file mode 100644 index 0000000..ece31b5 --- /dev/null +++ b/samples/module-info-dsl-no-platform/app/src/testFunctional/java/org/example/app/test/AppFunctionalTest.java @@ -0,0 +1,25 @@ +package org.example.app.test; + +import org.junit.jupiter.api.Test; +import org.example.app.App; + +import java.io.IOException; +import java.io.InputStream; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class AppFunctionalTest { + + @Test + void testAppFunctional() throws IOException { + assertEquals("org.example.app", App.class.getModule().getName()); + assertEquals("org.example.app.test.functional", AppFunctionalTest.class.getModule().getName()); + try (InputStream is = AppFunctionalTest.class.getResourceAsStream("/data.txt")) { + assertNotNull(is); + assertEquals("DEF", new String(is.readAllBytes(), UTF_8)); + } + } + +} \ No newline at end of file diff --git a/samples/module-info-dsl-no-platform/app/src/testFunctional/resources/data.txt b/samples/module-info-dsl-no-platform/app/src/testFunctional/resources/data.txt new file mode 100644 index 0000000..59ecf1e --- /dev/null +++ b/samples/module-info-dsl-no-platform/app/src/testFunctional/resources/data.txt @@ -0,0 +1 @@ +DEF \ No newline at end of file diff --git a/samples/module-info-dsl-no-platform/build.gradle.kts b/samples/module-info-dsl-no-platform/build.gradle.kts new file mode 100644 index 0000000..42b87b3 --- /dev/null +++ b/samples/module-info-dsl-no-platform/build.gradle.kts @@ -0,0 +1,3 @@ +plugins { + id("org.example.root") +} \ No newline at end of file diff --git a/samples/module-info-dsl-no-platform/build.out b/samples/module-info-dsl-no-platform/build.out new file mode 100644 index 0000000..3c2f8a1 --- /dev/null +++ b/samples/module-info-dsl-no-platform/build.out @@ -0,0 +1,38 @@ +> Task :lib:compileJava +> Task :lib:processResources NO-SOURCE +> Task :lib:classes +> Task :lib:jar +> Task :app:compileJava +> Task :app:processResources NO-SOURCE +> Task :app:classes +> Task :app:jar +> Task :app:startScripts +> Task :app:distTar +> Task :app:distZip +> Task :app:assemble +> Task :app:compileTestJava +> Task :app:processTestResources +> Task :app:testClasses +> Task :app:test +> Task :app:compileTestFunctionalJava +> Task :app:processTestFunctionalResources +> Task :app:testFunctionalClasses +> Task :app:testFunctionalJar +> Task :app:testFunctional +> Task :app:check +> Task :app:build +> Task :lib:assemble +> Task :lib:compileTestJava +> Task :lib:processTestResources +> Task :lib:testClasses +> Task :lib:test +> Task :lib:compileTestFunctionalJava +> Task :lib:processTestFunctionalResources +> Task :lib:testFunctionalClasses +> Task :lib:testFunctionalJar +> Task :lib:testFunctional +> Task :lib:check +> Task :lib:build + +> Task :app:run +[main] INFO org.example.app.App - App running... \ No newline at end of file diff --git a/samples/module-info-dsl-no-platform/build.sample.conf b/samples/module-info-dsl-no-platform/build.sample.conf new file mode 100644 index 0000000..cbb84e0 --- /dev/null +++ b/samples/module-info-dsl-no-platform/build.sample.conf @@ -0,0 +1,2 @@ +executable: gradlew +expected-output-file: build.out \ No newline at end of file diff --git a/samples/module-info-dsl-no-platform/gradle/plugins/build.gradle.kts b/samples/module-info-dsl-no-platform/gradle/plugins/build.gradle.kts new file mode 100644 index 0000000..069d2ab --- /dev/null +++ b/samples/module-info-dsl-no-platform/gradle/plugins/build.gradle.kts @@ -0,0 +1,9 @@ +plugins { + `kotlin-dsl` +} + +dependencies { + implementation("com.autonomousapps:dependency-analysis-gradle-plugin:1.20.0") + implementation("org.gradlex:java-module-dependencies:1.3.1") + implementation("org.gradlex:java-module-testing:1.2") +} \ No newline at end of file diff --git a/samples/module-info-dsl-no-platform/gradle/plugins/settings.gradle.kts b/samples/module-info-dsl-no-platform/gradle/plugins/settings.gradle.kts new file mode 100644 index 0000000..89015ed --- /dev/null +++ b/samples/module-info-dsl-no-platform/gradle/plugins/settings.gradle.kts @@ -0,0 +1,6 @@ +dependencyResolutionManagement { + repositories.gradlePluginPortal() +} + +// This is for testing against the latest version of the plugin, remove if you copied this for a real project +includeBuild(extra.properties["pluginLocation"] ?: rootDir.parentFile.parentFile.parentFile.parent) diff --git a/samples/module-info-dsl-no-platform/gradle/plugins/src/main/kotlin/org.example.java-base.gradle.kts b/samples/module-info-dsl-no-platform/gradle/plugins/src/main/kotlin/org.example.java-base.gradle.kts new file mode 100644 index 0000000..adfd8a9 --- /dev/null +++ b/samples/module-info-dsl-no-platform/gradle/plugins/src/main/kotlin/org.example.java-base.gradle.kts @@ -0,0 +1,19 @@ +plugins { + id("java") + id("org.gradlex.java-module-dependencies") + id("org.gradlex.java-module-testing") +} + +group = "org.example" + +java.toolchain.languageVersion.set(JavaLanguageVersion.of(17)) +testing.suites.register("testFunctional") +tasks.check { dependsOn(tasks.named("testFunctional")) } + +javaModuleDependencies { + versionsFromPlatformAndConsistentResolution(":app", ":app") +} + +tasks.withType().configureEach { + jvmArgs("-Dorg.slf4j.simpleLogger.defaultLogLevel=error") +} diff --git a/samples/module-info-dsl-no-platform/gradle/plugins/src/main/kotlin/org.example.java-module-app.gradle.kts b/samples/module-info-dsl-no-platform/gradle/plugins/src/main/kotlin/org.example.java-module-app.gradle.kts new file mode 100644 index 0000000..0451028 --- /dev/null +++ b/samples/module-info-dsl-no-platform/gradle/plugins/src/main/kotlin/org.example.java-module-app.gradle.kts @@ -0,0 +1,5 @@ +plugins { + id("org.example.java-base") + id("application") + id("org.gradlex.java-module-versions") +} diff --git a/samples/module-info-dsl-no-platform/gradle/plugins/src/main/kotlin/org.example.java-module.gradle.kts b/samples/module-info-dsl-no-platform/gradle/plugins/src/main/kotlin/org.example.java-module.gradle.kts new file mode 100644 index 0000000..2b2a77a --- /dev/null +++ b/samples/module-info-dsl-no-platform/gradle/plugins/src/main/kotlin/org.example.java-module.gradle.kts @@ -0,0 +1,5 @@ +plugins { + id("org.example.java-base") + id("java-library") +} + diff --git a/samples/module-info-dsl-no-platform/gradle/plugins/src/main/kotlin/org.example.root.gradle.kts b/samples/module-info-dsl-no-platform/gradle/plugins/src/main/kotlin/org.example.root.gradle.kts new file mode 100644 index 0000000..0843ac8 --- /dev/null +++ b/samples/module-info-dsl-no-platform/gradle/plugins/src/main/kotlin/org.example.root.gradle.kts @@ -0,0 +1,3 @@ +plugins { + id("com.autonomousapps.dependency-analysis") +} diff --git a/samples/module-info-dsl-no-platform/lib/build.gradle.kts b/samples/module-info-dsl-no-platform/lib/build.gradle.kts new file mode 100644 index 0000000..f7f5297 --- /dev/null +++ b/samples/module-info-dsl-no-platform/lib/build.gradle.kts @@ -0,0 +1,7 @@ +plugins { + id("org.example.java-module") +} + +testModuleInfo { + requires("org.junit.jupiter.api") +} diff --git a/samples/module-info-dsl-no-platform/lib/src/main/java/module-info.java b/samples/module-info-dsl-no-platform/lib/src/main/java/module-info.java new file mode 100644 index 0000000..88381e5 --- /dev/null +++ b/samples/module-info-dsl-no-platform/lib/src/main/java/module-info.java @@ -0,0 +1,7 @@ +module org.example.lib { + requires transitive com.fasterxml.jackson.databind; + + requires java.logging; // JDK module + + exports org.example.lib; +} \ No newline at end of file diff --git a/samples/module-info-dsl-no-platform/lib/src/main/java/org/example/lib/Lib.java b/samples/module-info-dsl-no-platform/lib/src/main/java/org/example/lib/Lib.java new file mode 100644 index 0000000..030b9bf --- /dev/null +++ b/samples/module-info-dsl-no-platform/lib/src/main/java/org/example/lib/Lib.java @@ -0,0 +1,10 @@ +package org.example.lib; + +import com.fasterxml.jackson.databind.ObjectMapper; + +public class Lib { + + public void process(ObjectMapper mapper) { + + } +} diff --git a/samples/module-info-dsl-no-platform/lib/src/test/java/org/example/lib/LibTest.java b/samples/module-info-dsl-no-platform/lib/src/test/java/org/example/lib/LibTest.java new file mode 100644 index 0000000..1ceda14 --- /dev/null +++ b/samples/module-info-dsl-no-platform/lib/src/test/java/org/example/lib/LibTest.java @@ -0,0 +1,23 @@ +package org.example.lib; + +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.io.InputStream; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +class LibTest { + + @Test + void testLib() throws IOException { + assertEquals("org.example.lib", Lib.class.getModule().getName()); + assertEquals("org.example.lib", LibTest.class.getModule().getName()); + try (InputStream is = LibTest.class.getResourceAsStream("/data.txt")) { + assertNotNull(is); + assertEquals("2*21", new String(is.readAllBytes(), UTF_8)); + } + } +} diff --git a/samples/module-info-dsl-no-platform/lib/src/test/resources/data.txt b/samples/module-info-dsl-no-platform/lib/src/test/resources/data.txt new file mode 100644 index 0000000..23861f7 --- /dev/null +++ b/samples/module-info-dsl-no-platform/lib/src/test/resources/data.txt @@ -0,0 +1 @@ +2*21 \ No newline at end of file diff --git a/samples/module-info-dsl-no-platform/lib/src/testFunctional/java/module-info.java b/samples/module-info-dsl-no-platform/lib/src/testFunctional/java/module-info.java new file mode 100644 index 0000000..aa4e13d --- /dev/null +++ b/samples/module-info-dsl-no-platform/lib/src/testFunctional/java/module-info.java @@ -0,0 +1,4 @@ +open module org.example.lib.test.functional { + requires org.example.lib; + requires org.junit.jupiter.api; +} diff --git a/samples/module-info-dsl-no-platform/lib/src/testFunctional/java/org/example/lib/test/LibFunctionalTest.java b/samples/module-info-dsl-no-platform/lib/src/testFunctional/java/org/example/lib/test/LibFunctionalTest.java new file mode 100644 index 0000000..863d5a7 --- /dev/null +++ b/samples/module-info-dsl-no-platform/lib/src/testFunctional/java/org/example/lib/test/LibFunctionalTest.java @@ -0,0 +1,24 @@ +package org.example.lib.test; + +import org.example.lib.Lib; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.io.InputStream; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +class LibFunctionalTest { + + @Test + void testLibFunctional() throws IOException { + assertEquals("org.example.lib", Lib.class.getModule().getName()); + assertEquals("org.example.lib.test.functional", LibFunctionalTest.class.getModule().getName()); + try (InputStream is = LibFunctionalTest.class.getResourceAsStream("/data.txt")) { + assertNotNull(is); + assertEquals("42", new String(is.readAllBytes(), UTF_8)); + } + } +} diff --git a/samples/module-info-dsl-no-platform/lib/src/testFunctional/resources/data.txt b/samples/module-info-dsl-no-platform/lib/src/testFunctional/resources/data.txt new file mode 100644 index 0000000..f70d7bb --- /dev/null +++ b/samples/module-info-dsl-no-platform/lib/src/testFunctional/resources/data.txt @@ -0,0 +1 @@ +42 \ No newline at end of file diff --git a/samples/module-info-dsl-no-platform/settings.gradle.kts b/samples/module-info-dsl-no-platform/settings.gradle.kts new file mode 100644 index 0000000..afbd5b5 --- /dev/null +++ b/samples/module-info-dsl-no-platform/settings.gradle.kts @@ -0,0 +1,8 @@ +pluginManagement { + includeBuild("gradle/plugins") +} +dependencyResolutionManagement { + repositories.mavenCentral() +} + +include("app", "lib") diff --git a/samples/module-info-dsl/app/build.gradle.kts b/samples/module-info-dsl/app/build.gradle.kts new file mode 100644 index 0000000..e7ff3f3 --- /dev/null +++ b/samples/module-info-dsl/app/build.gradle.kts @@ -0,0 +1,17 @@ +plugins { + id("org.example.java-module-app") +} + +application { + applicationDefaultJvmArgs = listOf("-ea") + mainClass.set("org.example.app.App") + mainModule.set("org.example.app") +} + +mainModuleInfo { + runtimeOnly("org.slf4j.simple") +} + +testModuleInfo { + requires("org.junit.jupiter.api") +} diff --git a/samples/module-info-dsl/app/src/main/java/module-info.java b/samples/module-info-dsl/app/src/main/java/module-info.java new file mode 100644 index 0000000..cc02079 --- /dev/null +++ b/samples/module-info-dsl/app/src/main/java/module-info.java @@ -0,0 +1,6 @@ +module org.example.app { + requires org.example.lib; + requires org.slf4j; + + exports org.example.app; +} \ No newline at end of file diff --git a/samples/module-info-dsl/app/src/main/java/org/example/app/App.java b/samples/module-info-dsl/app/src/main/java/org/example/app/App.java new file mode 100644 index 0000000..deb09b1 --- /dev/null +++ b/samples/module-info-dsl/app/src/main/java/org/example/app/App.java @@ -0,0 +1,16 @@ +package org.example.app; + +import org.example.lib.Lib; +import org.slf4j.LoggerFactory; + +public class App { + + public static void main(String[] args) { + LoggerFactory.getLogger(App.class).info("App running..."); + doWork(); + } + + public static void doWork() { + new Lib(); + } +} \ No newline at end of file diff --git a/samples/module-info-dsl/app/src/test/java/org/example/app/AppTest.java b/samples/module-info-dsl/app/src/test/java/org/example/app/AppTest.java new file mode 100644 index 0000000..c50a6ee --- /dev/null +++ b/samples/module-info-dsl/app/src/test/java/org/example/app/AppTest.java @@ -0,0 +1,26 @@ +package org.example.app; + +import org.example.lib.Lib; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.io.InputStream; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class AppTest { + + @Test + public void testApp() throws IOException { + assertEquals("org.example.lib", Lib.class.getModule().getName()); + assertEquals("org.example.app", App.class.getModule().getName()); + assertEquals("org.example.app", AppTest.class.getModule().getName()); + try (InputStream is = AppTest.class.getResourceAsStream("/data.txt")) { + assertNotNull(is); + assertEquals("ABC", new String(is.readAllBytes(), UTF_8)); + } + } + +} \ No newline at end of file diff --git a/samples/module-info-dsl/app/src/test/resources/data.txt b/samples/module-info-dsl/app/src/test/resources/data.txt new file mode 100644 index 0000000..48b83b8 --- /dev/null +++ b/samples/module-info-dsl/app/src/test/resources/data.txt @@ -0,0 +1 @@ +ABC \ No newline at end of file diff --git a/samples/module-info-dsl/app/src/testFunctional/java/module-info.java b/samples/module-info-dsl/app/src/testFunctional/java/module-info.java new file mode 100644 index 0000000..f54dadf --- /dev/null +++ b/samples/module-info-dsl/app/src/testFunctional/java/module-info.java @@ -0,0 +1,4 @@ +open module org.example.app.test.functional { + requires org.example.app; + requires org.junit.jupiter.api; +} \ No newline at end of file diff --git a/samples/module-info-dsl/app/src/testFunctional/java/org/example/app/test/AppFunctionalTest.java b/samples/module-info-dsl/app/src/testFunctional/java/org/example/app/test/AppFunctionalTest.java new file mode 100644 index 0000000..ece31b5 --- /dev/null +++ b/samples/module-info-dsl/app/src/testFunctional/java/org/example/app/test/AppFunctionalTest.java @@ -0,0 +1,25 @@ +package org.example.app.test; + +import org.junit.jupiter.api.Test; +import org.example.app.App; + +import java.io.IOException; +import java.io.InputStream; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class AppFunctionalTest { + + @Test + void testAppFunctional() throws IOException { + assertEquals("org.example.app", App.class.getModule().getName()); + assertEquals("org.example.app.test.functional", AppFunctionalTest.class.getModule().getName()); + try (InputStream is = AppFunctionalTest.class.getResourceAsStream("/data.txt")) { + assertNotNull(is); + assertEquals("DEF", new String(is.readAllBytes(), UTF_8)); + } + } + +} \ No newline at end of file diff --git a/samples/module-info-dsl/app/src/testFunctional/resources/data.txt b/samples/module-info-dsl/app/src/testFunctional/resources/data.txt new file mode 100644 index 0000000..59ecf1e --- /dev/null +++ b/samples/module-info-dsl/app/src/testFunctional/resources/data.txt @@ -0,0 +1 @@ +DEF \ No newline at end of file diff --git a/samples/module-info-dsl/build.gradle.kts b/samples/module-info-dsl/build.gradle.kts new file mode 100644 index 0000000..42b87b3 --- /dev/null +++ b/samples/module-info-dsl/build.gradle.kts @@ -0,0 +1,3 @@ +plugins { + id("org.example.root") +} \ No newline at end of file diff --git a/samples/module-info-dsl/build.out b/samples/module-info-dsl/build.out new file mode 100644 index 0000000..34f1381 --- /dev/null +++ b/samples/module-info-dsl/build.out @@ -0,0 +1,41 @@ +> Task :lib:compileJava +> Task :lib:processResources NO-SOURCE +> Task :lib:classes +> Task :lib:jar +> Task :app:compileJava +> Task :app:processResources NO-SOURCE +> Task :app:classes +> Task :app:jar +> Task :app:startScripts +> Task :app:distTar +> Task :app:distZip +> Task :app:assemble +> Task :app:compileTestJava +> Task :app:processTestResources +> Task :app:testClasses +> Task :app:test +> Task :app:compileTestFunctionalJava +> Task :app:processTestFunctionalResources +> Task :app:testFunctionalClasses +> Task :app:testFunctionalJar +> Task :app:testFunctional +> Task :app:check +> Task :app:build +> Task :lib:assemble +> Task :lib:compileTestJava +> Task :lib:processTestResources +> Task :lib:testClasses +> Task :lib:test +> Task :lib:compileTestFunctionalJava +> Task :lib:processTestFunctionalResources +> Task :lib:testFunctionalClasses +> Task :lib:testFunctionalJar +> Task :lib:testFunctional +> Task :lib:check +> Task :lib:build +> Task :versions:assemble UP-TO-DATE +> Task :versions:check UP-TO-DATE +> Task :versions:build UP-TO-DATE + +> Task :app:run +[main] INFO org.example.app.App - App running... diff --git a/samples/module-info-dsl/build.sample.conf b/samples/module-info-dsl/build.sample.conf new file mode 100644 index 0000000..cbb84e0 --- /dev/null +++ b/samples/module-info-dsl/build.sample.conf @@ -0,0 +1,2 @@ +executable: gradlew +expected-output-file: build.out \ No newline at end of file diff --git a/samples/module-info-dsl/gradle/plugins/build.gradle.kts b/samples/module-info-dsl/gradle/plugins/build.gradle.kts new file mode 100644 index 0000000..069d2ab --- /dev/null +++ b/samples/module-info-dsl/gradle/plugins/build.gradle.kts @@ -0,0 +1,9 @@ +plugins { + `kotlin-dsl` +} + +dependencies { + implementation("com.autonomousapps:dependency-analysis-gradle-plugin:1.20.0") + implementation("org.gradlex:java-module-dependencies:1.3.1") + implementation("org.gradlex:java-module-testing:1.2") +} \ No newline at end of file diff --git a/samples/module-info-dsl/gradle/plugins/settings.gradle.kts b/samples/module-info-dsl/gradle/plugins/settings.gradle.kts new file mode 100644 index 0000000..89015ed --- /dev/null +++ b/samples/module-info-dsl/gradle/plugins/settings.gradle.kts @@ -0,0 +1,6 @@ +dependencyResolutionManagement { + repositories.gradlePluginPortal() +} + +// This is for testing against the latest version of the plugin, remove if you copied this for a real project +includeBuild(extra.properties["pluginLocation"] ?: rootDir.parentFile.parentFile.parentFile.parent) diff --git a/samples/module-info-dsl/gradle/plugins/src/main/kotlin/org.example.java-base.gradle.kts b/samples/module-info-dsl/gradle/plugins/src/main/kotlin/org.example.java-base.gradle.kts new file mode 100644 index 0000000..3f67ea0 --- /dev/null +++ b/samples/module-info-dsl/gradle/plugins/src/main/kotlin/org.example.java-base.gradle.kts @@ -0,0 +1,19 @@ +plugins { + id("java") + id("org.gradlex.java-module-dependencies") + id("org.gradlex.java-module-testing") +} + +group = "org.example" + +java.toolchain.languageVersion.set(JavaLanguageVersion.of(17)) +testing.suites.register("testFunctional") +tasks.check { dependsOn(tasks.named("testFunctional")) } + +javaModuleDependencies { + versionsFromPlatformAndConsistentResolution(":versions", ":app") +} + +tasks.withType().configureEach { + jvmArgs("-Dorg.slf4j.simpleLogger.defaultLogLevel=error") +} diff --git a/samples/module-info-dsl/gradle/plugins/src/main/kotlin/org.example.java-module-app.gradle.kts b/samples/module-info-dsl/gradle/plugins/src/main/kotlin/org.example.java-module-app.gradle.kts new file mode 100644 index 0000000..3b98c9b --- /dev/null +++ b/samples/module-info-dsl/gradle/plugins/src/main/kotlin/org.example.java-module-app.gradle.kts @@ -0,0 +1,4 @@ +plugins { + id("org.example.java-base") + id("application") +} diff --git a/samples/module-info-dsl/gradle/plugins/src/main/kotlin/org.example.java-module-versions.gradle.kts b/samples/module-info-dsl/gradle/plugins/src/main/kotlin/org.example.java-module-versions.gradle.kts new file mode 100644 index 0000000..dd92ca9 --- /dev/null +++ b/samples/module-info-dsl/gradle/plugins/src/main/kotlin/org.example.java-module-versions.gradle.kts @@ -0,0 +1,4 @@ +plugins { + id("java-platform") + id("org.gradlex.java-module-versions") +} \ No newline at end of file diff --git a/samples/module-info-dsl/gradle/plugins/src/main/kotlin/org.example.java-module.gradle.kts b/samples/module-info-dsl/gradle/plugins/src/main/kotlin/org.example.java-module.gradle.kts new file mode 100644 index 0000000..2b2a77a --- /dev/null +++ b/samples/module-info-dsl/gradle/plugins/src/main/kotlin/org.example.java-module.gradle.kts @@ -0,0 +1,5 @@ +plugins { + id("org.example.java-base") + id("java-library") +} + diff --git a/samples/module-info-dsl/gradle/plugins/src/main/kotlin/org.example.root.gradle.kts b/samples/module-info-dsl/gradle/plugins/src/main/kotlin/org.example.root.gradle.kts new file mode 100644 index 0000000..0843ac8 --- /dev/null +++ b/samples/module-info-dsl/gradle/plugins/src/main/kotlin/org.example.root.gradle.kts @@ -0,0 +1,3 @@ +plugins { + id("com.autonomousapps.dependency-analysis") +} diff --git a/samples/module-info-dsl/lib/build.gradle.kts b/samples/module-info-dsl/lib/build.gradle.kts new file mode 100644 index 0000000..6464a48 --- /dev/null +++ b/samples/module-info-dsl/lib/build.gradle.kts @@ -0,0 +1,9 @@ +plugins { + id("org.example.java-module") +} + +testModuleInfo { + requires("org.junit.jupiter.api") +} + +// println(configurations.compileClasspath.get().files) \ No newline at end of file diff --git a/samples/module-info-dsl/lib/src/main/java/module-info.java b/samples/module-info-dsl/lib/src/main/java/module-info.java new file mode 100644 index 0000000..88381e5 --- /dev/null +++ b/samples/module-info-dsl/lib/src/main/java/module-info.java @@ -0,0 +1,7 @@ +module org.example.lib { + requires transitive com.fasterxml.jackson.databind; + + requires java.logging; // JDK module + + exports org.example.lib; +} \ No newline at end of file diff --git a/samples/module-info-dsl/lib/src/main/java/org/example/lib/Lib.java b/samples/module-info-dsl/lib/src/main/java/org/example/lib/Lib.java new file mode 100644 index 0000000..030b9bf --- /dev/null +++ b/samples/module-info-dsl/lib/src/main/java/org/example/lib/Lib.java @@ -0,0 +1,10 @@ +package org.example.lib; + +import com.fasterxml.jackson.databind.ObjectMapper; + +public class Lib { + + public void process(ObjectMapper mapper) { + + } +} diff --git a/samples/module-info-dsl/lib/src/test/java/org/example/lib/LibTest.java b/samples/module-info-dsl/lib/src/test/java/org/example/lib/LibTest.java new file mode 100644 index 0000000..1ceda14 --- /dev/null +++ b/samples/module-info-dsl/lib/src/test/java/org/example/lib/LibTest.java @@ -0,0 +1,23 @@ +package org.example.lib; + +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.io.InputStream; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +class LibTest { + + @Test + void testLib() throws IOException { + assertEquals("org.example.lib", Lib.class.getModule().getName()); + assertEquals("org.example.lib", LibTest.class.getModule().getName()); + try (InputStream is = LibTest.class.getResourceAsStream("/data.txt")) { + assertNotNull(is); + assertEquals("2*21", new String(is.readAllBytes(), UTF_8)); + } + } +} diff --git a/samples/module-info-dsl/lib/src/test/resources/data.txt b/samples/module-info-dsl/lib/src/test/resources/data.txt new file mode 100644 index 0000000..23861f7 --- /dev/null +++ b/samples/module-info-dsl/lib/src/test/resources/data.txt @@ -0,0 +1 @@ +2*21 \ No newline at end of file diff --git a/samples/module-info-dsl/lib/src/testFunctional/java/module-info.java b/samples/module-info-dsl/lib/src/testFunctional/java/module-info.java new file mode 100644 index 0000000..aa4e13d --- /dev/null +++ b/samples/module-info-dsl/lib/src/testFunctional/java/module-info.java @@ -0,0 +1,4 @@ +open module org.example.lib.test.functional { + requires org.example.lib; + requires org.junit.jupiter.api; +} diff --git a/samples/module-info-dsl/lib/src/testFunctional/java/org/example/lib/test/LibFunctionalTest.java b/samples/module-info-dsl/lib/src/testFunctional/java/org/example/lib/test/LibFunctionalTest.java new file mode 100644 index 0000000..863d5a7 --- /dev/null +++ b/samples/module-info-dsl/lib/src/testFunctional/java/org/example/lib/test/LibFunctionalTest.java @@ -0,0 +1,24 @@ +package org.example.lib.test; + +import org.example.lib.Lib; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.io.InputStream; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +class LibFunctionalTest { + + @Test + void testLibFunctional() throws IOException { + assertEquals("org.example.lib", Lib.class.getModule().getName()); + assertEquals("org.example.lib.test.functional", LibFunctionalTest.class.getModule().getName()); + try (InputStream is = LibFunctionalTest.class.getResourceAsStream("/data.txt")) { + assertNotNull(is); + assertEquals("42", new String(is.readAllBytes(), UTF_8)); + } + } +} diff --git a/samples/module-info-dsl/lib/src/testFunctional/resources/data.txt b/samples/module-info-dsl/lib/src/testFunctional/resources/data.txt new file mode 100644 index 0000000..f70d7bb --- /dev/null +++ b/samples/module-info-dsl/lib/src/testFunctional/resources/data.txt @@ -0,0 +1 @@ +42 \ No newline at end of file diff --git a/samples/module-info-dsl/settings.gradle.kts b/samples/module-info-dsl/settings.gradle.kts new file mode 100644 index 0000000..a6d5172 --- /dev/null +++ b/samples/module-info-dsl/settings.gradle.kts @@ -0,0 +1,9 @@ +pluginManagement { + includeBuild("gradle/plugins") +} +dependencyResolutionManagement { + repositories.mavenCentral() +} + +include("app", "lib") +include("versions") diff --git a/samples/module-info-dsl/versions/build.gradle.kts b/samples/module-info-dsl/versions/build.gradle.kts new file mode 100644 index 0000000..1f8d2ae --- /dev/null +++ b/samples/module-info-dsl/versions/build.gradle.kts @@ -0,0 +1,10 @@ +plugins { + id("org.example.java-module-versions") +} + +moduleInfo { + version("org.slf4j", "2.0.7") + version("org.slf4j.simple", "2.0.7") + version("com.fasterxml.jackson.databind", "2.14.0") + version("org.junit.jupiter.api", "5.9.3") +}