Skip to content

Commit

Permalink
Java Modules - additional plugins and rules
Browse files Browse the repository at this point in the history
  • Loading branch information
jjohannes committed Dec 4, 2023
1 parent 16d7391 commit 97a4b8f
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 94 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ plugins {
}

application {
mainModule.set("org.example.product.app")
mainClass.set("org.example.product.app.Application")
}
31 changes: 12 additions & 19 deletions gradle/platform/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,20 @@ plugins {
}

dependencies {
api(platform("com.fasterxml.jackson:jackson-bom:2.13.2.20220328"))
api(platform("com.google.inject:guice-bom:5.1.0"))
api(platform("org.apache.httpcomponents:httpcomponents-client:4.5.13")) { because ("see HttpComponentsPlatformRule") } // Parent as Anchor for Alignment BOM
api(platform("com.fasterxml.jackson:jackson-bom:2.13.4"))
api(platform("org.apache.poi:poi:5.2.2")) { because ("see PoiPlatformRule") } // Central component as Anchor for Alignment BOM
api(platform("org.jboss.resteasy:resteasy-bom:4.7.6.Final")) { (this as ExternalModuleDependency).version { reject("[5.0.0.Final,)") } }
api(platform("org.junit:junit-bom:5.7.2")) { (this as ExternalModuleDependency).version { reject("[5.8.0,)") } } // Do not Upgrade to 5.8: https://github.com/gradle/gradle/issues/18627
api(platform("org.mockito:mockito-bom:4.5.1"))
api(platform("org.slf4j:slf4j-parent:1.7.36")) { because ("see Slf4jPlatformRule") } // Parent as Anchor for Alignment BOM
api(platform("org.mockito:mockito-bom:4.8.0"))
api(platform("org.slf4j:slf4j-parent:2.0.3")) { because ("see Slf4jPlatformRule") } // Parent as Anchor for Alignment BOM
}

dependencies.constraints {
api("com.github.racc:typesafeconfig-guice:0.1.0")
api("com.sun.activation:jakarta.activation:1.2.2") { version { reject("[2.0.0,)") } } // Upgrade to 2.x requires newer Jakarta APIs
api("com.sun.mail:jakarta.mail:1.6.7") { version { reject("[2.0.0,)") } } // Upgrade to 2.x requires newer Jakarta APIs
api("jakarta.inject:jakarta.inject-api:1.0.5") { version { reject("[2.0.0,)") } } // Upgrade to 2.x requires newer Jakarta APIs
api("jakarta.servlet:jakarta.servlet-api:4.0.4") { version { reject("[5.0.0,)") } } // Stay Tomcat 8 compatible
api("org.apache.commons:commons-lang3:3.9")
api("org.apache.solr:solr-solrj:7.7.3") { version { reject("[8.0.0,)") } } // API changes in 8 require production code changes
api("org.apache.velocity:velocity-engine-core:2.3")
api("org.apache.zookeeper:zookeeper:3.8.0")
api("org.assertj:assertj-core:3.22.0")
api("org.opensaml:opensaml:2.6.4")
api("org.reflections:reflections:0.9.11") { version { reject("[0.9.12,)") } } // Upgrade breaks 'com.github.racc:typesafeconfig-guice'
moduleInfo {
version("com.google.common", "30.1-jre")
version("jakarta.activation") { require("1.2.2"); reject("[2.0.0,)") } // Upgrade to 2.x requires newer Jakarta APIs
version("jakarta.mail") { require("1.6.7"); reject("[2.0.0,)") } // Upgrade to 2.x requires newer Jakarta APIs
version("jakarta.servlet", "6.0.0")
version("java.inject") { require("1.0.5"); reject("[2.0.0,)") } // Upgrade to 2.x requires newer Jakarta APIs
version("javax.annotations.jsr305", "3.0.2")
version("org.assertj.core", "3.22.0")
version("velocity.engine.core", "2.3")
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id("java-platform")
id("org.example.base")
id("org.gradlex.java-module-versions")
}

// Depend on other Platforms/BOMs to align versions for libraries that consist of multiple components (like Jackson)
Expand Down
2 changes: 2 additions & 0 deletions gradle/plugins/dependency-rules-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ dependencies {
implementation(platform(project(":plugins-platform")))

implementation("dev.jacomet.gradle.plugins:logging-capabilities")
implementation("org.gradlex:extra-java-module-info")
implementation("org.gradlex:java-ecosystem-capabilities")
implementation("org.gradlex:java-module-dependencies")
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import org.example.metadatarules.fixdependencies.TypesafeConfigGuiceRule
import org.example.metadatarules.fixdependencies.GuavaCleanupRule
import org.example.metadatarules.status.ComponentStatusRule
import org.example.metadatarules.versionalignment.HttpComponentsPlatformRule
import org.example.metadatarules.versionalignment.PoiPlatformRule
import org.example.metadatarules.versionalignment.Slf4jPlatformRule
import org.example.metadatarules.versionalignment.ParentPomAsPlatformRule

plugins {
id("dev.jacomet.logging-capabilities")
id("org.gradlex.java-ecosystem-capabilities")
id("org.example.java-modules-dependency-rules")
}

// Configure logging capabilities plugin to default to Slf4JSimple
Expand All @@ -18,14 +18,12 @@ dependencies.components {
all<ComponentStatusRule>()

// Fix dependencies
withModule<TypesafeConfigGuiceRule>(TypesafeConfigGuiceRule.TYPESAFE_CONFIG_GUICE_MODULE)
withModule<GuavaCleanupRule>(GuavaCleanupRule.GUAVA_MODULE)

// Define 'Alignment Platforms' (platforms for multi-component libraries without published BOM)
withModule<HttpComponentsPlatformRule>(HttpComponentsPlatformRule.HTTP_COMPONENTS_CLIENT)
withModule<PoiPlatformRule>(PoiPlatformRule.POI_COMMON)
withModule<Slf4jPlatformRule>(Slf4jPlatformRule.SLF4J_PARENT)

// Make parents usable as pure 'Alignment Platforms' - remove all constraints that do not concern the alignment
withModule<ParentPomAsPlatformRule>(HttpComponentsPlatformRule.HTTP_COMPONENTS_CLIENT)
withModule<ParentPomAsPlatformRule>(Slf4jPlatformRule.SLF4J_PARENT)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
plugins {
id("org.gradlex.extra-java-module-info")
id("org.gradlex.java-module-dependencies")
}

extraJavaModuleInfo {
failOnAutomaticModules.set(true)

module("com.google.code.findbugs:jsr305", "javax.annotations.jsr305") {
exports("javax.annotation")
requireAllDefinedDependencies()
}
module("com.google.guava:guava", "com.google.common") {
exportAllPackages()
requireAllDefinedDependencies()
}
module("com.github.virtuald:curvesapi", "com.github.virtuald.curvesapi") { // required by org.apache.poi.poi
exportAllPackages()
requireAllDefinedDependencies()
}
module("com.zaxxer:SparseBitSet", "SparseBitSet") { // required by org.apache.poi.poi
exports("com.zaxxer.sparsebits")
requireAllDefinedDependencies()
}
module("commons-codec:commons-codec", "org.apache.commons.codec") { // required by org.apache.poi.poi
exportAllPackages()
requireAllDefinedDependencies()
}
module("org.apache.commons:commons-collections4", "org.apache.commons.collections4") { // required by org.apache.poi.poi
exportAllPackages()
requireAllDefinedDependencies()
}
module("org.apache.commons:commons-compress", "org.apache.commons.compress") { // required by org.apache.poi.poi
exportAllPackages()
requireAllDefinedDependencies()
}
module("commons-io:commons-io", "org.apache.commons.io") { // required by org.apache.poi.poi
exportAllPackages()
requireAllDefinedDependencies()
}
module("org.apache.commons:commons-lang3", "org.apache.commons.lang3") { // required by velocity
exportAllPackages()
requireAllDefinedDependencies()
}
module("org.apache.commons:commons-math3", "commons.math3") { // required by org.apache.poi.poi
exportAllPackages()
requireAllDefinedDependencies()
}
module("org.apache.velocity:velocity-engine-core", "velocity.engine.core") {
exportAllPackages()
requireAllDefinedDependencies()
}
module("org.hamcrest:hamcrest-core", "org.hamcrest.core") {
exportAllPackages()
requireAllDefinedDependencies()
}
knownModule("org.slf4j:slf4j-api", "org.slf4j")
}

javaModuleDependencies {
// Override because there are multiple options
moduleNameToGA.put("jakarta.activation", "com.sun.activation:jakarta.activation")
moduleNameToGA.put("jakarta.mail", "com.sun.mail:jakarta.mail")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.example.metadatarules.fixdependencies

import org.gradle.api.artifacts.CacheableRule
import org.gradle.api.artifacts.ComponentMetadataContext
import org.gradle.api.artifacts.ComponentMetadataRule

/**
* Removes dependencies of Guava that we do not need and that are not Java Modules
*/
@CacheableRule
abstract class GuavaCleanupRule : ComponentMetadataRule {
companion object {
const val GUAVA_MODULE = "com.google.guava:guava"
}

override fun execute(context: ComponentMetadataContext) {
context.details.allVariants {
withDependencies {
removeIf { it.name == "failureaccess" }
removeIf { it.name == "j2objc-annotations" }
removeIf { it.name == "checker-qual" }
removeIf { it.name == "error_prone_annotations" }
}
}
}
}

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions gradle/plugins/java-base-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ dependencies {
implementation(platform(project(":plugins-platform")))

implementation(project(":base-plugins"))
implementation("org.gradlex:java-module-dependencies")
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.gradlex.javamodule.dependencies.dsl.GradleOnlyDirectives

plugins {
id("java")
id("jacoco") // Record test coverage data during test execution
Expand Down Expand Up @@ -25,11 +27,14 @@ tasks.withType<Test>().configureEach {
}

// Configure common test runtime dependencies for *all* projects
dependencies {
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
testRuntimeOnly("org.slf4j:slf4j-simple")
extensions.configure<GradleOnlyDirectives>("testModuleInfo") {
runtimeOnly("org.junit.jupiter.engine")
runtimeOnly("org.slf4j.simple")
}

// We use the merge Jar feature of 'extra-java-module-info' and javaModulesMergeJars also needs to get version from somewhere
configurations.javaModulesMergeJars.get().shouldResolveConsistentlyWith(configurations["appRuntimeClasspath"])

// Add a 'compileAll' task to run all of Java compilation in one go
tasks.register("compileAll") {
group = LifecycleBasePlugin.BUILD_GROUP
Expand Down
1 change: 1 addition & 0 deletions gradle/plugins/java-library-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ dependencies {
implementation(platform(project(":plugins-platform")))

implementation(project(":java-base-plugins"))
implementation("org.gradlex:java-module-testing")
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
id("java-library")
id("org.example.java")
id("org.gradlex.java-module-testing")
}
3 changes: 3 additions & 0 deletions gradle/plugins/plugins-platform/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ plugins {
dependencies.constraints {
api("dev.jacomet.gradle.plugins:logging-capabilities:0.11.1")
api("io.fuchs.gradle.classpath-collision-detector:classpath-collision-detector:0.3")
api("org.gradlex:extra-java-module-info:1.6")
api("org.gradlex:java-ecosystem-capabilities:1.3.1")
api("org.gradlex:java-module-dependencies:1.5")
api("org.gradlex:java-module-testing:1.3")
api("org.owasp:dependency-check-gradle:7.4.4")
}

0 comments on commit 97a4b8f

Please sign in to comment.