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

Prepare several Gradle 9.0 deprecations #5686

Merged
merged 6 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ tasks.trimShadedJar.doLast {
def trimmed = tasks.trimShadedJar.outJarFiles[0].toPath()

ant.jar(destfile: trimmed.toString(), update: true, duplicate: 'fail') {
zipfileset(src: tasks.shadedJar.archivePath) {
zipfileset(src: tasks.shadedJar.archiveFile.get().asFile) {
include(name: 'META-INF/versions/**')
}

Expand Down
2 changes: 1 addition & 1 deletion examples/dropwizard/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ dependencies {

task runDropwizardExample(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = application.mainClass.get()
mainClass = application.mainClass.get()
args = ['server', 'server.yaml']
}
6 changes: 3 additions & 3 deletions gradle/scripts/.gitrepo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[subrepo]
remote = https://github.com/line/gradle-scripts
branch = main
commit = d31f74478150e01781adafb43ed51aec6c830126
parent = 33f1eeba8058f126922efffa0dd0ec87a06fd8be
commit = a3211a7ec874b42fc7dc5a84b3960a705d5fc34c
parent = c66b9211afdd86ce388b5b77b99fc7ffad6c0888
method = merge
cmdver = 0.4.5
cmdver = 0.4.6
28 changes: 0 additions & 28 deletions gradle/scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ 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)

<!-- /MarkdownTOC -->
Expand Down Expand Up @@ -99,7 +98,6 @@ 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
Expand All @@ -120,7 +118,6 @@ 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.
Expand Down Expand Up @@ -675,31 +672,6 @@ 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
Expand Down
4 changes: 2 additions & 2 deletions gradle/scripts/lib/bom.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ configure(projectsWithFlags('bom')) {
"Please check bomGroups property", project.name)
}
subs = bomGroups.get(project.path)
if (!(subs.value instanceof List)) {
throw new IllegalStateException("bomGroups' value must be a List: ${subs.value}")
if (!(subs instanceof List)) {
throw new IllegalStateException("bomGroups' value must be a List: ${subs}")
}
}

Expand Down
60 changes: 11 additions & 49 deletions gradle/scripts/lib/common-info.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,17 @@ allprojects {
ext {
artifactId = {
// Use the overridden one if available.
def overriddenArtifactId = findOverridden('artifactIdOverrides', project)
if (overriddenArtifactId != null) {
return overriddenArtifactId
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<String, String> e : overrides.entrySet()) {
if (rootProject.project(e.key) == project) {
return e.value
}
}
}

// Generate from the project names otherwise.
Expand All @@ -62,49 +70,3 @@ 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<String, String> e : overrides.entrySet()) {
if (rootProject.project(e.key) == project) {
return String.valueOf(e.value)
}
}
}

return null
}
5 changes: 5 additions & 0 deletions gradle/scripts/lib/common-publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ if (publishToStaging) {
password = project.findProperty(publishPasswordProperty)
}
}

transitionCheckOptions {
maxRetries.set(100)
delayBetween.set(Duration.ofSeconds(20))
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion gradle/scripts/lib/java-javadoc.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,11 @@ class DownloadJavadocPackageListTask extends DefaultTask {
conn.disconnect()
} catch (e) {
tmpListFile.delete()
logger.log(LogLevel.WARN, "Download failed: ${e}", e)
if (project.gradle.startParameter.showStacktrace == ShowStacktrace.ALWAYS_FULL) {
logger.log(LogLevel.WARN, "Download failed: ${e}", e)
} else {
logger.log(LogLevel.WARN, "Download failed: ${e}")
}
}

return success
Expand Down
2 changes: 1 addition & 1 deletion gradle/scripts/lib/java-publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ configure(projectsWithFlags('publish', 'java')) {
jarOverrideFile = tasks.trimShadedJar.outJarFiles.find() as File
jarOverrideTask = tasks.trimShadedJar
} else if (tasks.findByName('shadedJar')) {
jarOverrideFile = tasks.shadedJar.archivePath
jarOverrideFile = tasks.shadedJar.archiveFile.get().asFile
jarOverrideTask = tasks.shadedJar
}
if (jarOverrideFile != null) {
Expand Down
25 changes: 7 additions & 18 deletions gradle/scripts/lib/java-shade.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,12 @@ 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'

// 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

Expand All @@ -57,7 +46,7 @@ configure(relocatedProjects) {
description: 'Extracts the shaded main JAR.',
dependsOn: tasks.shadedJar) {

from(zipTree(tasks.shadedJar.archivePath))
from(zipTree(tasks.shadedJar.archiveFile.get().asFile))
from(sourceSets.main.output.classesDirs) {
// Add the JAR resources excluded in the 'shadedJar' task.
include '**/*.jar'
Expand All @@ -81,7 +70,7 @@ configure(relocatedProjects) {
description: 'Extracts the shaded test JAR.',
dependsOn: tasks.shadedTestJar) {

from(zipTree(tasks.shadedTestJar.archivePath))
from(zipTree(tasks.shadedTestJar.archiveFile.get().asFile))
from(sourceSets.test.output.classesDirs) {
// Add the JAR resources excluded in the 'shadedTestJar' task.
include '**/*.jar'
Expand All @@ -107,7 +96,7 @@ configure(relocatedProjects) {
dependsOn it.tasks.shadedTestJar.path
}

def shadedFile = tasks.shadedJar.archivePath
def shadedFile = tasks.shadedJar.archiveFile.get().asFile
def shadedAndTrimmedFile = file(shadedFile.path.replaceFirst('-untrimmed-', '-shaded-'))

injars shadedFile
Expand All @@ -118,11 +107,11 @@ configure(relocatedProjects) {

// Include all other shaded JARs so that ProGuard does not trim the classes and methods
// that are used actually.
injars tasks.shadedTestJar.archivePath
injars tasks.shadedTestJar.archiveFile.get().asFile
relocatedProjects.each {
if (it != project && !it.hasFlags('no_aggregation')) {
injars it.tasks.shadedJar.archivePath
injars it.tasks.shadedTestJar.archivePath
injars it.tasks.shadedJar.archiveFile.get().asFile
injars it.tasks.shadedTestJar.archiveFile.get().asFile
}
}

Expand Down Expand Up @@ -336,7 +325,7 @@ private Configuration configureShadedTestImplementConfiguration(
if (recursedProject.tasks.findByName('trimShadedJar')) {
project.dependencies.add(shadedJarTestImplementation.name, files(recursedProject.tasks.trimShadedJar.outJarFiles))
} else if (recursedProject.tasks.findByName('shadedJar')) {
project.dependencies.add(shadedJarTestImplementation.name, files(recursedProject.tasks.shadedJar.archivePath))
project.dependencies.add(shadedJarTestImplementation.name, files(recursedProject.tasks.shadedJar.archiveFile.get().asFile))
}

def shadedDependencyNames = project.ext.relocations.collect { it['name'] }
Expand Down
20 changes: 3 additions & 17 deletions gradle/scripts/lib/java.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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')))
Expand Down Expand Up @@ -50,7 +49,9 @@ configure(projectsWithFlags('java')) {
apply plugin: 'idea'
apply plugin: 'jvm-test-suite'

archivesBaseName = project.ext.artifactId
base {
archivesName = project.ext.artifactId
}

// Delete the generated source directory on clean.
ext {
Expand Down Expand Up @@ -140,12 +141,6 @@ 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.
Expand All @@ -161,15 +156,6 @@ 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') {
Expand Down
10 changes: 1 addition & 9 deletions gradle/scripts/lib/prerequisite.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ plugins {
''')
}

['group', 'version', 'projectName', 'projectUrl', 'inceptionYear', 'licenseName', 'licenseUrl', 'scmUrl', 'scmConnection',
['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
Expand All @@ -34,12 +31,7 @@ publishUrlForRelease=https://oss.sonatype.org/service/local/staging/deploy/maven
publishUrlForSnapshot=https://oss.sonatype.org/content/repositories/snapshots/
publishUsernameProperty=ossrhUsername
publishPasswordProperty=ossrhPassword
publishSignatureRequired=true
versionPattern=^[0-9]+\\\\.[0-9]+\\\\.[0-9]+$
googleAnalyticsId=UA-XXXXXXXX
javaSourceCompatibility=1.8
javaTargetCompatibility=1.8
automaticModuleNames=false
''')
}
}
6 changes: 5 additions & 1 deletion gradle/scripts/settings-flags.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,9 @@ static void afterProjectsWithFlags(Project project, Iterable<?> flags, Closure<S

// We add a "virtual project", with no source code, to control dependency management using Gradle's platform
// functionality.
def virtualProjectsPath = "${rootDir}/build/virtual-projects"
includeWithFlags ':dependencyManagement', 'dependencyManagement'
project(':dependencyManagement').projectDir = file("${rootProject.projectDir}/build/dependencyManagement")
project(":dependencyManagement").with {
projectDir = file("${virtualProjectsPath}/dependencyManagement")
projectDir.mkdirs()
}
2 changes: 1 addition & 1 deletion thrift/thrift0.13/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ext {
// NB: Keep this same with 'armeria-thrift0.9'.
tasks.shadedJar.exclude 'com/linecorp/armeria/common/thrift/ThriftListenableFuture*'
tasks.shadedJar.doLast {
ant.jar(update: true, destfile: tasks.shadedJar.archivePath) {
ant.jar(update: true, destfile: tasks.shadedJar.archiveFile.get().asFile) {
sourceSets.main.output.classesDirs.each { classesDir ->
fileset(dir: "${classesDir}",
includes: 'com/linecorp/armeria/common/thrift/ThriftListenableFuture*')
Expand Down
2 changes: 1 addition & 1 deletion thrift/thrift0.14/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ tasks.sourcesJar.from "${thrift013ProjectDir}/src/main/resources"
// NB: Keep this same with ':thrift0.13'.
tasks.shadedJar.exclude 'com/linecorp/armeria/common/thrift/ThriftListenableFuture*'
tasks.shadedJar.doLast {
ant.jar(update: true, destfile: tasks.shadedJar.archivePath) {
ant.jar(update: true, destfile: tasks.shadedJar.archiveFile.get().asFile) {
sourceSets.main.output.classesDirs.each { classesDir ->
fileset(dir: "$classesDir",
includes: 'com/linecorp/armeria/common/thrift/ThriftListenableFuture*')
Expand Down
2 changes: 1 addition & 1 deletion thrift/thrift0.15/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ tasks.sourcesJar.from "${thrift013ProjectDir}/src/main/resources"
// NB: Keep this same with ':thrift0.13'.
tasks.shadedJar.exclude 'com/linecorp/armeria/common/thrift/ThriftListenableFuture*'
tasks.shadedJar.doLast {
ant.jar(update: true, destfile: tasks.shadedJar.archivePath) {
ant.jar(update: true, destfile: tasks.shadedJar.archiveFile.get().asFile) {
sourceSets.main.output.classesDirs.each { classesDir ->
fileset(dir: "$classesDir",
includes: 'com/linecorp/armeria/common/thrift/ThriftListenableFuture*')
Expand Down
2 changes: 1 addition & 1 deletion thrift/thrift0.16/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ tasks.sourcesJar.from "${thrift013ProjectDir}/src/main/resources"
// NB: Keep this same with ':thrift0.13'.
tasks.shadedJar.exclude 'com/linecorp/armeria/common/thrift/ThriftListenableFuture*'
tasks.shadedJar.doLast {
ant.jar(update: true, destfile: tasks.shadedJar.archivePath) {
ant.jar(update: true, destfile: tasks.shadedJar.archiveFile.get().asFile) {
sourceSets.main.output.classesDirs.each { classesDir ->
fileset(dir: "$classesDir",
includes: 'com/linecorp/armeria/common/thrift/ThriftListenableFuture*')
Expand Down
Loading
Loading