diff --git a/build.gradle.kts b/build.gradle.kts index 72bd5c3..23a58a1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,15 +7,12 @@ tasks.wrapper { } subprojects { - group = rootProject.group version = rootProject.version - - repositories { - mavenCentral() - } } -tasks.register("clean") { - delete("build") +tasks.register("clean") { + description = "Deletes the build directory" + group = "Build" + delete(layout.buildDirectory) } diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..cc02e63 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,7 @@ +plugins { + `kotlin-dsl` +} + +repositories { + gradlePluginPortal() +} diff --git a/gradle/publishing.gradle.kts b/buildSrc/src/main/kotlin/decycle.publishing.gradle.kts similarity index 62% rename from gradle/publishing.gradle.kts rename to buildSrc/src/main/kotlin/decycle.publishing.gradle.kts index 02f1125..7e9af30 100644 --- a/gradle/publishing.gradle.kts +++ b/buildSrc/src/main/kotlin/decycle.publishing.gradle.kts @@ -1,29 +1,32 @@ -apply(plugin = "signing") +import java.util.Base64 + +plugins { + signing +} + +val ossrhHost = "https://ossrh-staging-api.central.sonatype.com" configure { repositories { maven { name = "local" - url = file("${rootProject.buildDir}/repository").toURI() + url = rootProject.layout.buildDirectory.dir("repository").get().asFile.toURI() } maven { - // see https://central.sonatype.org/publish/generate-portal-token/ - val ossrhUsername: String? by project - val ossrhPassword: String? by project name = "sonatype" - url = uri("https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/") + url = uri("$ossrhHost/service/local/staging/deploy/maven2/") credentials { - username = ossrhUsername - password = ossrhPassword + username = System.getenv("OSSRH_USERNAME") + password = System.getenv("OSSRH_PASSWORD") } } } publications { // publication mavenJava is provided by the io.freefair.maven-publish-java plugin - getByName("mavenJava").run { + withType().matching { it.name == "mavenJava" }.configureEach { pom { - name.set(project.extra["displayName"] as String) - description.set(project.description) + name.set(provider { project.extra["displayName"] as String }) + description.set(provider { project.description }) url.set("https://github.com/obecker/decycle") licenses { license { @@ -47,25 +50,21 @@ configure { } } -tasks.withType() { +tasks.withType().configureEach { val isSnapshot = version.toString().endsWith("-SNAPSHOT") if (repository.name == "sonatype" && isSnapshot) { enabled = false } } -tasks.withType() { +tasks.withType().configureEach { onlyIf { project.hasProperty("signing.keyId") } } -tasks.withType() { - doLast { - // workaround for https://bugs.openjdk.java.net/browse/JDK-8215291 in Java 11 - file("${destinationDir}/search.js").appendText("getURLPrefix = function(ui) { return ''; };\n") - } - (options as StandardJavadocDocletOptions).links("https://docs.oracle.com/en/java/javase/11/docs/api/") +tasks.withType().configureEach { + (options as StandardJavadocDocletOptions).links("https://docs.oracle.com/en/java/javase/17/docs/api/") } val postToSonatype by tasks.registering { @@ -73,11 +72,11 @@ val postToSonatype by tasks.registering { description = "Finalizes the publication by sending a POST request to OSSRH" // see https://central.sonatype.org/publish/publish-portal-ossrh-staging-api/#1-modify-your-ci-script doLast { - val ossrhUsername: String? by project - val ossrhPassword: String? by project + val ossrhUsername = System.getenv("OSSRH_USERNAME") + val ossrhPassword = System.getenv("OSSRH_PASSWORD") val ossrhNamespace = "de.obqo" - val url = "https://ossrh-staging-api.central.sonatype.com/manual/upload/defaultRepository/$ossrhNamespace" - val authToken = java.util.Base64.getEncoder().encodeToString("$ossrhUsername:$ossrhPassword".toByteArray()) + val url = "$ossrhHost/manual/upload/defaultRepository/$ossrhNamespace" + val authToken = Base64.getEncoder().encodeToString("$ossrhUsername:$ossrhPassword".toByteArray()) val authHeader = "Authorization: Bearer $authToken" val process = ProcessBuilder("curl", "-X", "POST", "-H", authHeader, url) .inheritIO() diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts index 50a328a..188a155 100644 --- a/lib/build.gradle.kts +++ b/lib/build.gradle.kts @@ -7,13 +7,12 @@ plugins { `java-library` alias(libs.plugins.lombok) alias(libs.plugins.maven.publish.java) + id("decycle.publishing") } description = "Java library for detecting and reporting package cycles" val displayName by extra("Decycle Lib") -apply(from = rootProject.file("gradle/publishing.gradle.kts")) - buildscript { repositories { mavenCentral() @@ -71,6 +70,8 @@ tasks.withType().configureEach { val extractWebJars = tasks.register("extractWebjars") { description = "Extract webjar resources to generated/resources" + inputs.files(buildscript.configurations.getByName("classpath")) + outputs.dir(generatedResources) val locator = WebJarAssetLocator() val classLoader = locator::class.java.classLoader @@ -106,7 +107,9 @@ tasks.processResources { dependsOn(extractWebJars) } -tasks["sourcesJar"].dependsOn(extractWebJars) +tasks.named("sourcesJar") { + dependsOn(extractWebJars) +} tasks.test { useJUnitPlatform() diff --git a/plugin-gradle/build.gradle.kts b/plugin-gradle/build.gradle.kts index 090a4c7..02e323e 100644 --- a/plugin-gradle/build.gradle.kts +++ b/plugin-gradle/build.gradle.kts @@ -8,15 +8,18 @@ plugins { val pluginId = "de.obqo.decycle" tasks.register("createClasspathManifest") { - val outputDir = file("$buildDir/classpathManifest") + val outputDir = layout.buildDirectory.dir("classpathManifest") + val outputFile = outputDir.map { it.file("plugin-classpath.txt") } val pluginClasspath = sourceSets.main.get().runtimeClasspath inputs.files(pluginClasspath) outputs.dir(outputDir) doLast { - outputDir.mkdirs() - file("$outputDir/plugin-classpath.txt").writeText(pluginClasspath.files.joinToString("\n")) + outputFile.get().asFile.apply { + parentFile.mkdirs() + writeText(pluginClasspath.files.joinToString("\n")) + } } } @@ -31,7 +34,7 @@ dependencies { testImplementation("org.junit.jupiter:junit-jupiter-api") testRuntimeOnly("org.junit.platform:junit-platform-launcher") testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine") - testRuntimeOnly(files(tasks.getByName("createClasspathManifest"))) + testRuntimeOnly(files(tasks.named("createClasspathManifest"))) } tasks.clean { @@ -55,7 +58,8 @@ java { tasks.processResources { inputs.property("version", version) doLast { - file("$buildDir/resources/main/META-INF/gradle-plugins/$pluginId.properties").appendText("tool-version=$version\n") + layout.buildDirectory.file("resources/main/META-INF/gradle-plugins/$pluginId.properties") + .get().asFile.appendText("tool-version=$version\n") } } diff --git a/plugin-maven/build.gradle.kts b/plugin-maven/build.gradle.kts index ba84448..8f7137e 100644 --- a/plugin-maven/build.gradle.kts +++ b/plugin-maven/build.gradle.kts @@ -2,13 +2,12 @@ plugins { `java-library` alias(libs.plugins.lombok) alias(libs.plugins.maven.plugin) + id("decycle.publishing") } description = "Maven plugin that executes decycle dependency checks" val displayName by extra("Decycle Maven Plugin") -apply(from = rootProject.file("gradle/publishing.gradle.kts")) - // see gradle/libs.versions.toml for libs. dependencies dependencies { implementation(project(":decycle-lib")) diff --git a/settings.gradle b/settings.gradle index 03cf3aa..dd54305 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,5 +1,12 @@ rootProject.name = 'decycle' +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + mavenCentral() + } +} + include('decycle-lib') include('decycle-gradle-plugin') include('decycle-maven-plugin')