Skip to content

Commit

Permalink
Upgrade to Gradle 8.4 (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
philipp94831 authored Mar 12, 2024
1 parent 76708a7 commit eb34ba6
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 44 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build-and-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ jobs:
build-and-publish:
name: Java Gradle
uses: bakdata/ci-templates/.github/workflows/[email protected]
with:
java-version: 17
secrets:
sonar-token: ${{ secrets.SONARCLOUD_TOKEN }}
sonar-organization: ${{ secrets.SONARCLOUD_ORGANIZATION }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
name: Java Gradle
uses: bakdata/ci-templates/.github/workflows/[email protected]
with:
java-version: 17
release-type: "${{ inputs.release-type }}"

secrets:
Expand Down
30 changes: 12 additions & 18 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ plugins {
id("com.bakdata.release") version "1.3.0"
// eat your own dog food - apply the plugins to this plugin project
id("com.bakdata.sonar") version "1.1.17"
id("com.bakdata.sonatype") version "1.3.1"
id("org.gradle.kotlin.kotlin-dsl") version "2.1.6" apply false
id("com.bakdata.sonatype") version "1.3.2"
id("org.gradle.kotlin.kotlin-dsl") version "4.1.2" apply false
id("com.gradle.plugin-publish") version "1.2.1" apply false
}

Expand Down Expand Up @@ -41,8 +41,9 @@ subprojects {
apply(plugin = "java")

configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}

apply(plugin = "java-gradle-plugin")
Expand All @@ -55,31 +56,24 @@ subprojects {
// description is only ready after evaluation
afterEvaluate {
configure<GradlePluginDevelopmentExtension> {
website.set("https://github.com/bakdata/gradle-plugins")
vcsUrl.set("https://github.com/bakdata/gradle-plugins")
plugins {
create("${project.name.capitalize()}Plugin") {
id = "com.bakdata.${project.name}"
implementationClass = "com.bakdata.gradle.${project.name.capitalize()}Plugin"
description = project.description
displayName = "Bakdata $name plugin"
tags = listOf("bakdata", name)
}
}
}

extensions.findByType(com.gradle.publish.PluginBundleExtension::class)?.apply {
// actual block of plugin portal config, need to be done on each subproject as the plugin does not support multi-module projects yet...
website = "https://github.com/bakdata/gradle-plugins"
vcsUrl = "https://github.com/bakdata/gradle-plugins"
tags = listOf("bakdata", name)
}
}

dependencies {
"testRuntimeOnly"("org.junit.jupiter:junit-jupiter-engine:5.3.0")
"testImplementation"("org.junit.jupiter:junit-jupiter-api:5.3.0")
"testImplementation"("org.assertj", "assertj-core", "3.11.1")
"testImplementation"("org.junit-pioneer", "junit-pioneer", "0.3.0")
val junitVersion = "5.10.2"
"testRuntimeOnly"("org.junit.jupiter:junit-jupiter-engine:$junitVersion")
"testImplementation"("org.junit.jupiter:junit-jupiter-api:$junitVersion")
"testImplementation"("org.assertj", "assertj-core", "3.25.3")
}
}

val sonarqube by tasks
sonarqube.enabled = false //FIXME requires Java 17
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion release/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ description = "Configures Gradle Release plugin for usage in CI"

dependencies {
implementation("net.researchgate", "gradle-release", "3.0.2")
implementation("gradle.plugin.org.hildan.gradle", "gradle-github-changelog", "1.12.1")
implementation("org.hildan.gradle", "gradle-github-changelog", "2.2.0")
}
14 changes: 8 additions & 6 deletions release/src/test/kotlin/com/bakdata/gradle/ReleasePluginTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import net.researchgate.release.ReleaseExtension
import net.researchgate.release.ReleasePlugin
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatCode
import org.assertj.core.api.Assertions.assertThatThrownBy
import org.assertj.core.api.Condition
import org.assertj.core.api.SoftAssertions
import org.gradle.api.Project
Expand All @@ -43,6 +44,7 @@ import org.gradle.testfixtures.ProjectBuilder
import org.hildan.github.changelog.plugin.GitHubChangelogExtension
import org.hildan.github.changelog.plugin.GitHubChangelogPlugin
import org.junit.jupiter.api.Test
import java.util.function.Consumer

internal class ReleasePluginTest {

Expand All @@ -64,16 +66,16 @@ internal class ReleasePluginTest {
.haveExactly(1, Condition({ it is ReleasePlugin }, "Has release plugin"))
.haveExactly(1, Condition({ it is GitHubChangelogPlugin }, "Has changelog plugin"))
softly.assertThat(project.extensions.findByType<ReleaseExtension>()?.git)
.satisfies {
.satisfies(Consumer { // TODO remove explicit Consumer once https://github.com/assertj/assertj/issues/2357 is resolved
softly.assertThat(it?.pushToRemote?.get()).isEqualTo("origin")
softly.assertThat(it?.requireBranch?.get()).isEqualTo("main")
}
})
softly.assertThat(project.extensions.findByType<GitHubChangelogExtension>())
.satisfies {
.satisfies(Consumer { // TODO remove explicit Consumer once https://github.com/assertj/assertj/issues/2357 is resolved
softly.assertThat(it?.githubRepository).isNull()
softly.assertThat(it?.futureVersionTag).isNull()
softly.assertThat(it?.sinceTag).isNull()
}
})
}
}

Expand Down Expand Up @@ -178,7 +180,7 @@ internal class ReleasePluginTest {
val parent = ProjectBuilder.builder().withName("parent").build()
val child1 = ProjectBuilder.builder().withName("child1").withParent(parent).build()

assertThatCode { child1.pluginManager.apply("com.bakdata.release") }
.satisfies { assertThat(it.cause).hasMessageContaining("top-level project") }
assertThatThrownBy { child1.pluginManager.apply("com.bakdata.release") }
.satisfies(Consumer { assertThat(it.cause).hasMessageContaining("top-level project") }) // TODO remove explicit Consumer once https://github.com/assertj/assertj/issues/2357 is resolved
}
}
5 changes: 1 addition & 4 deletions sonar/src/test/kotlin/com/bakdata/gradle/SonarPluginIT.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,11 @@ import org.gradle.testkit.runner.BuildTask
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.junitpioneer.jupiter.TempDirectory
import org.junitpioneer.jupiter.TempDirectory.TempDir
import org.junit.jupiter.api.io.TempDir
import java.io.File
import java.nio.file.Files
import java.nio.file.Path

@ExtendWith(TempDirectory::class)
internal class SonarPluginIT {
private fun taskWithPathAndOutcome(path: String, outcome: TaskOutcome):
Condition<BuildTask> = Condition({ it.path == path && it.outcome == outcome }, "Task $path=$outcome")
Expand Down
23 changes: 16 additions & 7 deletions sonar/src/test/kotlin/com/bakdata/gradle/SonarPluginTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ package com.bakdata.gradle

import org.assertj.core.api.Assertions
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatCode
import org.assertj.core.api.Assertions.assertThatThrownBy
import org.assertj.core.api.Condition
import org.assertj.core.api.SoftAssertions
import org.gradle.api.GradleException
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.internal.project.DefaultProject
import org.gradle.testfixtures.ProjectBuilder
import org.junit.jupiter.api.Test
import java.util.function.Consumer

internal class SonarPluginTest {
fun taskWithName(name: String): Condition<Task> = Condition({ it.name == name }, "Task with name $name")
Expand All @@ -53,7 +55,7 @@ internal class SonarPluginTest {
}.doesNotThrowAnyException()

SoftAssertions.assertSoftly { softly ->
softly.assertThat(project.tasks)
softly.assertThat(project.collectTasks())
.haveExactly(1, taskWithName("jacocoTestReport"))
.haveExactly(1, taskWithName("sonarqube"))
}
Expand All @@ -70,7 +72,7 @@ internal class SonarPluginTest {
}.doesNotThrowAnyException()

SoftAssertions.assertSoftly { softly ->
softly.assertThat(project.tasks)
softly.assertThat(project.collectTasks())
.haveExactly(1, taskWithName("jacocoTestReport"))
.haveExactly(1, taskWithName("sonarqube"))
}
Expand Down Expand Up @@ -98,7 +100,7 @@ internal class SonarPluginTest {
}

SoftAssertions.assertSoftly { softly ->
softly.assertThat(parent.tasks)
softly.assertThat(parent.collectTasks())
.haveExactly(0, taskWithName("jacocoTestReport"))
.haveExactly(1, taskWithName("sonarqube"))
}
Expand Down Expand Up @@ -126,7 +128,7 @@ internal class SonarPluginTest {
}

SoftAssertions.assertSoftly { softly ->
softly.assertThat(parent.tasks)
softly.assertThat(parent.collectTasks())
.haveExactly(0, taskWithName("jacocoTestReport"))
.haveExactly(1, taskWithName("sonarqube"))
}
Expand All @@ -137,7 +139,14 @@ internal class SonarPluginTest {
val parent = ProjectBuilder.builder().withName("parent").build()
val child1 = ProjectBuilder.builder().withName("child1").withParent(parent).build()

assertThatCode { child1.pluginManager.apply("com.bakdata.sonar") }
.satisfies { assertThat(it.cause).hasMessageContaining("top-level project") }
assertThatThrownBy { child1.pluginManager.apply("com.bakdata.sonar") }
.satisfies(Consumer { assertThat(it.cause).hasMessageContaining("top-level project") }) // TODO remove explicit Consumer once https://github.com/assertj/assertj/issues/2357 is resolved
}

private fun Project.collectTasks(): List<Task> = try {
tasks.toList()
} catch (e: GradleException) {
// FIXME bug since Gradle 7.3 https://github.com/gradle/gradle/issues/20301
if (e.message.equals("Could not create task ':init'.")) tasks.toList() else throw e
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,15 @@ import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.junitpioneer.jupiter.TempDirectory
import org.junitpioneer.jupiter.TempDirectory.TempDir
import org.junit.jupiter.api.io.TempDir
import ru.lanwen.wiremock.ext.WiremockResolver
import ru.lanwen.wiremock.ext.WiremockResolver.Wiremock
import java.io.File
import java.nio.file.Files
import java.nio.file.Path


@ExtendWith(TempDirectory::class, WiremockResolver::class)
@ExtendWith(WiremockResolver::class)
internal class SonatypePluginIT {
private fun taskWithPathAndOutcome(path: String, outcome: TaskOutcome):
Condition<BuildTask> = Condition({ it.path == path && it.outcome == outcome }, "Task $path=$outcome")
Expand Down
28 changes: 24 additions & 4 deletions sonatype/src/test/kotlin/com/bakdata/gradle/SonatypePluginTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,30 @@ package com.bakdata.gradle
import org.assertj.core.api.Assertions
import org.assertj.core.api.Condition
import org.assertj.core.api.SoftAssertions.assertSoftly
import org.gradle.api.GradleException
import org.gradle.api.Project
import org.gradle.api.ProjectConfigurationException
import org.gradle.api.Task
import org.gradle.api.internal.project.DefaultProject
import org.gradle.kotlin.dsl.apply
import org.gradle.testfixtures.ProjectBuilder
import org.junit.jupiter.api.Test
import java.io.File
import java.nio.file.Files
import java.util.function.Consumer


internal class SonatypePluginTest {
fun Project.evaluate() {
(this as DefaultProject).evaluate()
val defaultProject: DefaultProject = this as DefaultProject
try {
defaultProject.evaluate()
} catch (e: ProjectConfigurationException) {
// FIXME bug since Gradle 7.3 https://github.com/gradle/gradle/issues/20301
if (e.message.equals("Failed to apply plugin 'org.gradle.build-init'.")) {
defaultProject.evaluate()
}
}
}

fun taskWithName(name: String): Condition<Task> = Condition({ it.name == name }, "Task with name $name")
Expand Down Expand Up @@ -99,7 +110,7 @@ internal class SonatypePluginTest {
}

assertSoftly { softly ->
softly.assertThat(parent.tasks)
softly.assertThat(parent.collectTasks())
.haveExactly(0, taskWithName("signSonatypePublication"))
.haveExactly(0, taskWithName("publish"))
.haveExactly(0, taskWithName("publishToNexus"))
Expand All @@ -112,8 +123,17 @@ internal class SonatypePluginTest {
val parent = ProjectBuilder.builder().withName("parent").build()
val child1 = ProjectBuilder.builder().withName("child1").withParent(parent).build()

Assertions.assertThatCode { child1.apply(plugin = "com.bakdata.sonatype") }
.satisfies { Assertions.assertThat(it.cause).hasMessageContaining("top-level project") }
Assertions.assertThatThrownBy { child1.apply(plugin = "com.bakdata.sonatype") }
.satisfies(Consumer {
Assertions.assertThat(it.cause).hasMessageContaining("top-level project")
}) // TODO remove explicit Consumer once https://github.com/assertj/assertj/issues/2357 is resolved
}

private fun Project.collectTasks(): List<Task> = try {
tasks.toList()
} catch (e: GradleException) {
// FIXME bug since Gradle 7.3 https://github.com/gradle/gradle/issues/20301
if (e.message.equals("Could not create task ':init'.")) tasks.toList() else throw e
}

}
Expand Down

0 comments on commit eb34ba6

Please sign in to comment.