Skip to content

Commit

Permalink
Fix Gradle deprecations
Browse files Browse the repository at this point in the history
* Use `optional` configuration with variants instead of `feature`
* Use `io.freefair.aggregate-javadoc`
* Upgrade to Gradle `8.9`
* Some other minor ode clean in Gradle configs

(cherry picked from commit 4c1ac20)
  • Loading branch information
artembilan committed Aug 6, 2024
1 parent 3fdf468 commit 3f45067
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 83 deletions.
122 changes: 71 additions & 51 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ buildscript {
ext.kotlinVersion = '1.9.25'
ext.isCI = System.getenv('GITHUB_ACTION')
repositories {
mavenCentral()
gradlePluginPortal()
maven { url 'https://repo.spring.io/plugins-release-local' }
mavenCentral()
if (version.endsWith('SNAPSHOT')) {
maven { url 'https://repo.spring.io/snapshot' }
}
Expand All @@ -17,11 +16,11 @@ buildscript {

plugins {
id 'base'
id 'project-report'
id 'idea'
id 'org.ajoberstar.grgit' version '4.1.1'
id 'io.spring.nohttp' version '0.0.11'
id 'io.spring.dependency-management' version '1.1.6' apply false
id 'io.freefair.aggregate-javadoc' version '8.6'
}

apply plugin: 'io.spring.nohttp'
Expand Down Expand Up @@ -122,36 +121,55 @@ allprojects {

configure(javaProjects) { subproject ->
apply plugin: 'java-library'
apply plugin: 'java'
apply from: "${rootProject.projectDir}/gradle/publish-maven.gradle"
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'checkstyle'
apply plugin: 'kotlin'
apply plugin: 'kotlin-spring'

apply from: "${rootProject.projectDir}/gradle/publish-maven.gradle"

def scopeAttribute = Attribute.of('dependency.scope', String)

configurations {
optional {
attributes {
attribute(scopeAttribute, 'optional')
}
}

compileClasspath.extendsFrom(optional)
testCompileClasspath.extendsFrom(optional)
testRuntimeClasspath.extendsFrom(optional)
}

components.java.addVariantsFromConfiguration(configurations.optional) {
mapToOptional()
}

java {
withJavadocJar()
withSourcesJar()
registerFeature('optional') {
usingSourceSet(sourceSets.main)
}
}

compileJava {
sourceCompatibility = 17
targetCompatibility = 17
options.release = 17
}

compileTestJava {
sourceCompatibility = 17
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
options.encoding = 'UTF-8'
}

eclipse.project.natures += 'org.springframework.ide.eclipse.core.springnature'

// dependencies that are common across all java projects
dependencies {
attributesSchema {
attribute(scopeAttribute)
}

implementation "com.google.code.findbugs:jsr305:$googleJsr305Version"
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
Expand All @@ -168,7 +186,7 @@ configure(javaProjects) { subproject ->
exclude group: 'org.hamcrest'
}
testImplementation "org.hamcrest:hamcrest-core:$hamcrestVersion"
optionalApi "org.assertj:assertj-core:$assertjVersion"
optional "org.assertj:assertj-core:$assertjVersion"
}

// enable all compiler warnings; individual projects may customize further
Expand All @@ -185,7 +203,6 @@ configure(javaProjects) { subproject ->

maxHeapSize = '1536m'
useJUnitPlatform()

}

checkstyle {
Expand All @@ -202,7 +219,7 @@ configure(javaProjects) { subproject ->
}
}

task updateCopyrights {
tasks.register('updateCopyrights') {
onlyIf { !isCI }
inputs.files(modifiedFiles.filter { f -> f.path.contains(subproject.name) })
outputs.dir('build/classes')
Expand Down Expand Up @@ -275,28 +292,27 @@ project ('spring-kafka') {
exclude group: 'org.springframework'
}
api "org.apache.kafka:kafka-clients:$kafkaVersion"
optionalApi "org.apache.kafka:kafka-streams:$kafkaVersion"
optionalApi 'com.fasterxml.jackson.core:jackson-core'
optionalApi 'com.fasterxml.jackson.core:jackson-databind'
optionalApi 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8'
optionalApi 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
optionalApi 'com.fasterxml.jackson.datatype:jackson-datatype-joda'
optionalApi ('com.fasterxml.jackson.module:jackson-module-kotlin') {
optional "org.apache.kafka:kafka-streams:$kafkaVersion"
optional 'com.fasterxml.jackson.core:jackson-core'
optional 'com.fasterxml.jackson.core:jackson-databind'
optional 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8'
optional 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
optional 'com.fasterxml.jackson.datatype:jackson-datatype-joda'
optional ('com.fasterxml.jackson.module:jackson-module-kotlin') {
exclude group: 'org.jetbrains.kotlin'
}

// Spring Data projection message binding support
optionalApi ("org.springframework.data:spring-data-commons") {
optional ("org.springframework.data:spring-data-commons") {
exclude group: 'org.springframework'
exclude group: 'io.micrometer'
}
optionalApi "com.jayway.jsonpath:json-path:$jaywayJsonPathVersion"
optional "com.jayway.jsonpath:json-path:$jaywayJsonPathVersion"

optionalApi 'io.projectreactor:reactor-core'
optionalApi 'io.projectreactor.kafka:reactor-kafka'
optionalApi 'io.micrometer:micrometer-core'
api 'io.micrometer:micrometer-observation'
optionalApi 'io.micrometer:micrometer-tracing'
optional 'io.projectreactor:reactor-core'
optional 'io.projectreactor.kafka:reactor-kafka'
optional 'io.micrometer:micrometer-core'
optional 'io.micrometer:micrometer-tracing'

testImplementation project (':spring-kafka-test')
testImplementation 'io.projectreactor:reactor-test'
Expand All @@ -322,9 +338,7 @@ project('spring-kafka-bom') {
dependencies {
constraints {
javaProjects.sort { "$it.name" }.each {
if (it.name != 'spring-kafka-docs') {
api it
}
api it
}
}
}
Expand Down Expand Up @@ -365,12 +379,12 @@ project ('spring-kafka-test') {
}
api 'org.junit.jupiter:junit-jupiter-api'
api 'org.junit.platform:junit-platform-launcher'
optionalApi "org.hamcrest:hamcrest-core:$hamcrestVersion"
optionalApi "org.mockito:mockito-core:$mockitoVersion"
optionalApi ("junit:junit:$junit4Version") {
optional "org.hamcrest:hamcrest-core:$hamcrestVersion"
optional "org.mockito:mockito-core:$mockitoVersion"
optional ("junit:junit:$junit4Version") {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
optionalApi "org.apache.logging.log4j:log4j-core:$log4jVersion"
optional "org.apache.logging.log4j:log4j-core:$log4jVersion"
}
}

Expand Down Expand Up @@ -402,33 +416,38 @@ task filterMetricsDocsContent(type: Copy) {
filter { line -> line.replaceAll('org.springframework.kafka.support.micrometer.', '').replaceAll('^Fully qualified n', 'N') }
}

task api(type: Javadoc) {
group = 'Documentation'
description = 'Generates aggregated Javadoc API documentation.'
dependencies {
javaProjects.each {
javadoc it
}
}

javadoc {
title = "${rootProject.description} ${version} API"
options {
encoding = 'UTF-8'
memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PROTECTED
memberLevel = JavadocMemberLevel.PROTECTED
author = true
header = rootProject.description
header = project.description
use = true
overview = 'src/api/overview.html'
splitIndex = true
links(project.ext.javadocLinks)
addBooleanOption('Xdoclint:syntax', true) // only check syntax with doclint
}

source javaProjects.collect { project ->
project.sourceSets.main.allJava
}

classpath = files(javaProjects.collect { project ->
project.sourceSets.main.compileClasspath
})
destinationDir = new File(buildDir, 'api')
classpath = files().from { files(javaProjects.collect { it.sourceSets.main.compileClasspath }) }
}

tasks.register('api') {
group = 'Documentation'
description = 'Generates aggregated Javadoc API documentation.'
dependsOn javadoc
}

task docsZip(type: Zip, dependsOn: [':spring-kafka-docs:antora']) {
tasks.register('docsZip', Zip) {
dependsOn ':spring-kafka-docs:antora'
group = 'Distribution'
archiveClassifier = 'docs'
description = "Builds -${archiveClassifier} archive containing api and reference " +
Expand All @@ -438,7 +457,7 @@ task docsZip(type: Zip, dependsOn: [':spring-kafka-docs:antora']) {
include 'changelog.txt'
}

from(api) {
from(javadoc) {
into 'api'
}

Expand All @@ -447,7 +466,7 @@ task docsZip(type: Zip, dependsOn: [':spring-kafka-docs:antora']) {
}
}

task distZip(type: Zip, dependsOn: [docsZip]) { //, schemaZip]) {
tasks.register('distZip', Zip) {
group = 'Distribution'
archiveClassifier = 'dist'
description = "Builds -${archiveClassifier} archive, containing all jars and docs, " +
Expand Down Expand Up @@ -485,7 +504,8 @@ task distZip(type: Zip, dependsOn: [docsZip]) { //, schemaZip]) {

}

task dist(dependsOn: assemble) {
tasks.register('dist') {
dependsOn assemble
group = 'Distribution'
description = 'Builds -dist, -docs distribution archives.'
}
Expand Down
35 changes: 18 additions & 17 deletions gradle/docs.gradle
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
node {
version = '16.16.0'
}

antora {
version = '3.2.0-alpha.2'
playbook = file('src/main/antora/antora-playbook.yml')
options = ['to-dir' : project.layout.buildDirectory.dir('site').get().toString(), clean: true, fetch: !project.gradle.startParameter.offline, stacktrace: true]
options = [
'to-dir' : project.layout.buildDirectory.dir('site').get().toString(),
clean : true,
fetch : !project.gradle.startParameter.offline,
stacktrace: true
]
dependencies = [
'@antora/atlas-extension': '1.0.0-alpha.1',
'@antora/collector-extension': '1.0.0-alpha.3',
'@asciidoctor/tabs': '1.0.0-beta.3',
'@springio/antora-extensions': '1.4.2',
'@antora/atlas-extension' : '1.0.0-alpha.1',
'@antora/collector-extension' : '1.0.0-alpha.3',
'@asciidoctor/tabs' : '1.0.0-beta.3',
'@springio/antora-extensions' : '1.4.2',
'@springio/asciidoctor-extensions': '1.0.0-alpha.8',
]
}

tasks.named("generateAntoraYml") {
asciidocAttributes = project.provider( {
return ['project-version' : project.version,
'revnumber': project.version,
'spring-version': project.version,
tasks.named('generateAntoraYml') {
asciidocAttributes = project.provider({
return ['project-version': project.version,
'revnumber' : project.version,
'spring-version' : project.version,
]
} )
})
baseAntoraYmlFile = file('src/main/antora/antora.yml')
}

tasks.create(name: 'createAntoraPartials', type: Sync) {
tasks.register('createAntoraPartials', Sync) {
from { project.rootProject.tasks.filterMetricsDocsContent.outputs }
into layout.buildDirectory.dir('generated-antora-resources/modules/ROOT/partials')
}

tasks.create('generateAntoraResources') {
tasks.register('generateAntoraResources') {
dependsOn 'createAntoraPartials'
dependsOn 'generateAntoraYml'
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=3e1af3ae886920c3ac87f7a91f816c0c7c436f276a6eefdb3da152100fef72ae
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionSha256Sum=d725d707bfabd4dfdc958c624003b3c80accc03f7037b5122c4b1d0ef15cecab
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 5 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
22 changes: 12 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down Expand Up @@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
Loading

0 comments on commit 3f45067

Please sign in to comment.