diff --git a/gradle/scripts/.gitrepo b/gradle/scripts/.gitrepo index 4717c2daab6..63287449668 100644 --- a/gradle/scripts/.gitrepo +++ b/gradle/scripts/.gitrepo @@ -6,7 +6,7 @@ [subrepo] remote = https://github.com/line/gradle-scripts branch = main - commit = 99521b299c71479aff81130ff4cd6881c197bbef - parent = dbae312e51e33b324e80126c174f8a485e4084a3 + commit = 107037098222a5848f4049ecac74262108db5f63 + parent = f58ffb3d42529bc8f806d4b3afdd06476d161d31 method = merge - cmdver = 0.4.6 + cmdver = 0.4.5 diff --git a/gradle/scripts/README.md b/gradle/scripts/README.md index 3de234e76a3..f8a4e54a6c4 100644 --- a/gradle/scripts/README.md +++ b/gradle/scripts/README.md @@ -34,6 +34,7 @@ sensible defaults. By applying them, you can: - [Shading a multi-module project with `relocate` flag](#shading-a-multi-module-project-with-relocate-flag) - [Setting a Java target version with the `java(\\d+)` flag](#setting-a-java-target-version-with-the-javad-flag) - [Setting a Kotlin target version with the `kotlin(\\d+\\.\\d+)` flag](#setting-a-koltin-target-version-with-the-kotlindd-flag) +- [Automatic module names](#automatic-module-names) - [Tagging conveniently with `release` task](#tagging-conveniently-with-release-task) @@ -98,6 +99,7 @@ sensible defaults. By applying them, you can: ``` group=com.doe.john.myexample version=0.0.1-SNAPSHOT + versionPattern=^[0-9]+\\.[0-9]+\\.[0-9]+$ projectName=My Example projectUrl=https://www.example.com/ projectDescription=My example project @@ -118,6 +120,7 @@ sensible defaults. By applying them, you can: googleAnalyticsId=UA-XXXXXXXX javaSourceCompatibility=1.8 javaTargetCompatibility=1.8 + automaticModuleNames=false ``` 5. That's all. You now have two Java subprojects with sensible defaults. @@ -576,6 +579,7 @@ relocations [ { from: "com.google.common", to: "com.doe.john.myproject.shaded.gu Unshaded tests are disabled by default when a shading task is configured. If you want to run unshaded tests, you can specify `-PpreferShadedTests=false` option. + If you would like to remove specific files when shading the JAR, you may specify the `-PshadowExclusions=` option. @@ -678,6 +682,31 @@ However, if you want to compile a Kotlin module with a different language versio For example, `kotlin1.6` flag makes your Kotlin module compatible with language version 1.6 and API version 1.6. +## Automatic module names + +By specifying the `automaticModuleNames=true` property in `settings.gradle`, every `java` project's JAR +file will contain the `Automatic-Module-Name` property in its `MANIFEST.MF`, auto-generated from the group ID +and artifact ID. For example: + +- groupId: `com.example`, artifactId: `foo-bar` + - module name: `com.example.foo.bar` +- groupId: `com.example.foo`, artifactId: `foo-bar` + - module name: `com.example.foo.bar` + +If enabled, each project with `java` flag will have the `automaticModuleName` property. + +You can override the automatic module name of a certain project via the `automaticModuleNameOverrides` +extension property: + + ```groovy + ext { + // Change the automatic module name of project ':bar' to 'com.example.fubar'. + automaticModuleNameOverrides = [ + ':bar': 'com.example.fubar' + ] + } + ``` + ## Tagging conveniently with `release` task The task called `release` is added at the top level project. It will update the diff --git a/gradle/scripts/lib/common-info.gradle b/gradle/scripts/lib/common-info.gradle index 13666f21cf7..0f29c25407e 100644 --- a/gradle/scripts/lib/common-info.gradle +++ b/gradle/scripts/lib/common-info.gradle @@ -42,17 +42,9 @@ allprojects { ext { artifactId = { // Use the overridden one if available. - if (rootProject.ext.has('artifactIdOverrides')) { - def overrides = rootProject.ext.artifactIdOverrides - if (!(overrides instanceof Map)) { - throw new IllegalStateException("artifactIdOverrides must be a Map: ${overrides}") - } - - for (Map.Entry e : overrides.entrySet()) { - if (rootProject.project(e.key) == project) { - return e.value - } - } + def overriddenArtifactId = findOverridden('artifactIdOverrides', project) + if (overriddenArtifactId != null) { + return overriddenArtifactId } // Generate from the project names otherwise. @@ -70,3 +62,49 @@ allprojects { }.call() } } + +// Check whether to enable automatic module names. +def isAutomaticModuleNameEnabled = 'true' == rootProject.findProperty('automaticModuleNames') + +allprojects { + ext { + automaticModuleName = { + if (!isAutomaticModuleNameEnabled) { + return null + } + + // Use the overridden one if available. + def overriddenAutomaticModuleName = findOverridden('automaticModuleNameOverrides', project) + if (overriddenAutomaticModuleName != null) { + return overriddenAutomaticModuleName + } + + // Generate from the groupId and artifactId otherwise. + def groupIdComponents = String.valueOf(rootProject.group).split("\\.").toList() + def artifactIdComponents = + String.valueOf(project.ext.artifactId).replace('-', '.').split("\\.").toList() + if (groupIdComponents.last() == artifactIdComponents.first()) { + return String.join('.', groupIdComponents + artifactIdComponents.drop(1)) + } else { + return String.join('.', groupIdComponents + artifactIdComponents) + } + }.call() + } +} + +def findOverridden(String overridesPropertyName, Project project) { + if (rootProject.ext.has(overridesPropertyName)) { + def overrides = rootProject.ext.get(overridesPropertyName) + if (!(overrides instanceof Map)) { + throw new IllegalStateException("rootProject.ext.${overridesPropertyName} must be a Map: ${overrides}") + } + + for (Map.Entry e : overrides.entrySet()) { + if (rootProject.project(e.key) == project) { + return String.valueOf(e.value) + } + } + } + + return null +} diff --git a/gradle/scripts/lib/java-shade.gradle b/gradle/scripts/lib/java-shade.gradle index fb661b690c6..05c49d16de3 100644 --- a/gradle/scripts/lib/java-shade.gradle +++ b/gradle/scripts/lib/java-shade.gradle @@ -27,12 +27,16 @@ configure(relocatedProjects) { configureShadowTask(project, delegate, true) archiveBaseName.set("${project.archivesBaseName}-shaded") + // Exclude the legacy file listing. + exclude '/META-INF/INDEX.LIST' // Exclude the class signature files. exclude '/META-INF/*.SF' exclude '/META-INF/*.DSA' exclude '/META-INF/*.RSA' // Exclude the files generated by Maven exclude '/META-INF/maven/**' + // Exclude the module metadata that'll become invalid after relocation. + exclude '**/module-info.class' def shadowExclusions = [] if (rootProject.hasProperty('shadowExclusions')) { @@ -41,6 +45,13 @@ configure(relocatedProjects) { shadowExclusions.each { exclude it } + + // Set the 'Automatic-Module-Name' property in MANIFEST.MF. + if (project.ext.automaticModuleName != null) { + manifest { + attributes('Automatic-Module-Name': project.ext.automaticModuleName) + } + } } tasks.assemble.dependsOn tasks.shadedJar diff --git a/gradle/scripts/lib/java.gradle b/gradle/scripts/lib/java.gradle index b9ebc8cae0d..a70498ac852 100644 --- a/gradle/scripts/lib/java.gradle +++ b/gradle/scripts/lib/java.gradle @@ -1,5 +1,6 @@ import java.util.regex.Pattern +// Determine which version of JDK should be used for builds. def buildJdkVersion = Integer.parseInt(JavaVersion.current().getMajorVersion()) if (rootProject.hasProperty('buildJdkVersion')) { def jdkVersion = Integer.parseInt(String.valueOf(rootProject.findProperty('buildJdkVersion'))) @@ -141,6 +142,12 @@ configure(projectsWithFlags('java')) { registerFeature('optional') { usingSourceSet(sourceSets.main) } + + // Do not let Gradle infer the module path if automatic module name is enabled, + // because it means the JAR will rely on JDK's automatic module metadata generation. + if (project.ext.automaticModuleName != null) { + modularity.inferModulePath = false + } } // Set the sensible compiler options. @@ -156,6 +163,15 @@ configure(projectsWithFlags('java')) { options.compilerArgs += '-parameters' } + // Set the 'Automatic-Module-Name' property in 'MANIFEST.MF' if `automaticModuleName` is not null. + if (project.ext.automaticModuleName != null) { + tasks.named('jar') { + manifest { + attributes('Automatic-Module-Name': project.ext.automaticModuleName) + } + } + } + project.ext.configureFlakyTests = { Test testTask -> def flakyTests = rootProject.findProperty('flakyTests') if (flakyTests == 'true') { diff --git a/gradle/scripts/lib/prerequisite.gradle b/gradle/scripts/lib/prerequisite.gradle index 7a94d9b4f8e..4d6adea3999 100644 --- a/gradle/scripts/lib/prerequisite.gradle +++ b/gradle/scripts/lib/prerequisite.gradle @@ -9,12 +9,15 @@ plugins { ''') } -['projectName', 'projectUrl', 'inceptionYear', 'licenseName', 'licenseUrl', 'scmUrl', 'scmConnection', +['group', 'version', 'projectName', 'projectUrl', 'inceptionYear', 'licenseName', 'licenseUrl', 'scmUrl', 'scmConnection', 'scmDeveloperConnection', 'publishUrlForRelease', 'publishUrlForSnapshot', 'publishUsernameProperty', 'publishPasswordProperty'].each { if (rootProject.findProperty(it) == null) { throw new IllegalStateException('''Add project info properties to gradle.properties: +group=com.doe.john.myexample +version=0.0.1-SNAPSHOT +versionPattern=^[0-9]+\\\\.[0-9]+\\\\.[0-9]+$ projectName=My Example projectUrl=https://www.example.com/ projectDescription=My example project @@ -31,7 +34,11 @@ publishUrlForRelease=https://oss.sonatype.org/service/local/staging/deploy/maven publishUrlForSnapshot=https://oss.sonatype.org/content/repositories/snapshots/ publishUsernameProperty=ossrhUsername publishPasswordProperty=ossrhPassword -versionPattern=^[0-9]+\\\\.[0-9]+\\\\.[0-9]+$ +publishSignatureRequired=true +googleAnalyticsId=UA-XXXXXXXX +javaSourceCompatibility=1.8 +javaTargetCompatibility=1.8 +automaticModuleNames=false ''') } } diff --git a/gradle/scripts/lib/thrift/0.19/thrift.linux-aarch_64 b/gradle/scripts/lib/thrift/0.19/thrift.linux-aarch_64 deleted file mode 100755 index be76cbc7db2..00000000000 Binary files a/gradle/scripts/lib/thrift/0.19/thrift.linux-aarch_64 and /dev/null differ diff --git a/gradle/scripts/lib/thrift/0.19/thrift.linux-x86_64 b/gradle/scripts/lib/thrift/0.19/thrift.linux-x86_64 deleted file mode 100755 index 41199747949..00000000000 Binary files a/gradle/scripts/lib/thrift/0.19/thrift.linux-x86_64 and /dev/null differ diff --git a/gradle/scripts/lib/thrift/0.19/thrift.osx-aarch_64 b/gradle/scripts/lib/thrift/0.19/thrift.osx-aarch_64 deleted file mode 100755 index 55e0548d2f0..00000000000 Binary files a/gradle/scripts/lib/thrift/0.19/thrift.osx-aarch_64 and /dev/null differ diff --git a/gradle/scripts/lib/thrift/0.19/thrift.osx-x86_64 b/gradle/scripts/lib/thrift/0.19/thrift.osx-x86_64 deleted file mode 100755 index 97d766d490b..00000000000 Binary files a/gradle/scripts/lib/thrift/0.19/thrift.osx-x86_64 and /dev/null differ diff --git a/gradle/scripts/lib/thrift/0.19/thrift.windows-x86_64.exe b/gradle/scripts/lib/thrift/0.19/thrift.windows-x86_64.exe deleted file mode 100755 index ff12a4318d9..00000000000 Binary files a/gradle/scripts/lib/thrift/0.19/thrift.windows-x86_64.exe and /dev/null differ diff --git a/gradle/scripts/lib/thrift/0.20/thrift.linux-aarch_64 b/gradle/scripts/lib/thrift/0.20/thrift.linux-aarch_64 deleted file mode 100755 index 66f6be8320d..00000000000 Binary files a/gradle/scripts/lib/thrift/0.20/thrift.linux-aarch_64 and /dev/null differ diff --git a/gradle/scripts/lib/thrift/0.20/thrift.linux-x86_64 b/gradle/scripts/lib/thrift/0.20/thrift.linux-x86_64 deleted file mode 100755 index d47f6b0d827..00000000000 Binary files a/gradle/scripts/lib/thrift/0.20/thrift.linux-x86_64 and /dev/null differ diff --git a/gradle/scripts/lib/thrift/0.20/thrift.osx-aarch_64 b/gradle/scripts/lib/thrift/0.20/thrift.osx-aarch_64 deleted file mode 100755 index a8849dcaac3..00000000000 Binary files a/gradle/scripts/lib/thrift/0.20/thrift.osx-aarch_64 and /dev/null differ diff --git a/gradle/scripts/lib/thrift/0.20/thrift.osx-x86_64 b/gradle/scripts/lib/thrift/0.20/thrift.osx-x86_64 deleted file mode 100755 index 1b75a814dc2..00000000000 Binary files a/gradle/scripts/lib/thrift/0.20/thrift.osx-x86_64 and /dev/null differ diff --git a/gradle/scripts/lib/thrift/0.20/thrift.windows-x86_64.exe b/gradle/scripts/lib/thrift/0.20/thrift.windows-x86_64.exe deleted file mode 100755 index a51c13677e0..00000000000 Binary files a/gradle/scripts/lib/thrift/0.20/thrift.windows-x86_64.exe and /dev/null differ