Skip to content
Open
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
11 changes: 4 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ tasks.wrapper {
}

subprojects {

group = rootProject.group
version = rootProject.version

repositories {
mavenCentral()
}
}

tasks.register("clean") {
delete("build")
tasks.register<Delete>("clean") {
description = "Deletes the build directory"
group = "Build"
delete(layout.buildDirectory)
}
7 changes: 7 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
`kotlin-dsl`
}

repositories {
gradlePluginPortal()
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
apply(plugin = "signing")
import java.util.Base64

plugins {
signing
}

val ossrhHost = "https://ossrh-staging-api.central.sonatype.com"

configure<PublishingExtension> {
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<MavenPublication>("mavenJava").run {
withType<MavenPublication>().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 {
Expand All @@ -47,37 +50,33 @@ configure<PublishingExtension> {
}
}

tasks.withType<PublishToMavenRepository>() {
tasks.withType<PublishToMavenRepository>().configureEach {
val isSnapshot = version.toString().endsWith("-SNAPSHOT")
if (repository.name == "sonatype" && isSnapshot) {
enabled = false
}
}

tasks.withType<Sign>() {
tasks.withType<Sign>().configureEach {
onlyIf {
project.hasProperty("signing.keyId")
}
}

tasks.withType<Javadoc>() {
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<Javadoc>().configureEach {
(options as StandardJavadocDocletOptions).links("https://docs.oracle.com/en/java/javase/17/docs/api/")
}

val postToSonatype by tasks.registering {
group = "publishing"
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()
Expand Down
9 changes: 6 additions & 3 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -71,6 +70,8 @@ tasks.withType<Javadoc>().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
Expand Down Expand Up @@ -106,7 +107,9 @@ tasks.processResources {
dependsOn(extractWebJars)
}

tasks["sourcesJar"].dependsOn(extractWebJars)
tasks.named<Jar>("sourcesJar") {
dependsOn(extractWebJars)
}

tasks.test {
useJUnitPlatform()
Expand Down
14 changes: 9 additions & 5 deletions plugin-gradle/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
}
}

Expand All @@ -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 {
Expand All @@ -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")
}
}

Expand Down
3 changes: 1 addition & 2 deletions plugin-maven/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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.<xyz> dependencies
dependencies {
implementation(project(":decycle-lib"))
Expand Down
7 changes: 7 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
Loading