From 900a439bfa28ae03d995967474f28000333d2231 Mon Sep 17 00:00:00 2001 From: stephengold Date: Wed, 12 Jun 2024 13:09:50 -0700 Subject: [PATCH] buildscripts: migrate from Gradle DSL to Kotlin DSL --- build.gradle | 26 ------ build.gradle.kts | 24 +++++ library/build.gradle | 190 --------------------------------------- library/build.gradle.kts | 179 ++++++++++++++++++++++++++++++++++++ settings.gradle | 29 ------ settings.gradle.kts | 16 ++++ vorbis/build.gradle | 180 ------------------------------------- vorbis/build.gradle.kts | 169 ++++++++++++++++++++++++++++++++++ 8 files changed, 388 insertions(+), 425 deletions(-) delete mode 100644 build.gradle create mode 100644 build.gradle.kts delete mode 100644 library/build.gradle create mode 100644 library/build.gradle.kts delete mode 100644 settings.gradle create mode 100644 settings.gradle.kts delete mode 100644 vorbis/build.gradle create mode 100644 vorbis/build.gradle.kts diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 273cf73..0000000 --- a/build.gradle +++ /dev/null @@ -1,26 +0,0 @@ -// Gradle script to build the j-ogg-all project - -plugins { - id 'base' // to add a "clean" task to the root project -} - -ext { - group = 'com.github.stephengold' - version = '1.0.6-SNAPSHOT' - websiteUrl = 'https://github.com/stephengold/j-ogg-all' -} - -tasks.register('checkstyle') { - dependsOn ':library:checkstyleMain', ':vorbis:checkstyleMain' -} - -// Register publishing tasks: - -tasks.register('install') { - dependsOn ':library:install', 'vorbis:install' - description 'Installs Maven artifacts to the local repository.' -} -tasks.register('release') { - dependsOn 'library:release', 'vorbis:release' - description 'Stages Maven artifacts to Sonatype OSSRH.' -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..39a7289 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,24 @@ +// Gradle script to build the j-ogg-all project + +plugins { + `base` // to add a "clean" task to the root project +} + +ext { + set("version", "1.0.6-SNAPSHOT") +} + +tasks.register("checkstyle") { + dependsOn(":library:checkstyleMain", ":vorbis:checkstyleMain") +} + +// Register publishing tasks: + +tasks.register("install") { + dependsOn(":library:install", "vorbis:install") + description = "Installs Maven artifacts to the local repository." +} +tasks.register("release") { + dependsOn("library:release", "vorbis:release") + description = "Stages Maven artifacts to Sonatype OSSRH." +} diff --git a/library/build.gradle b/library/build.gradle deleted file mode 100644 index 0eaa33b..0000000 --- a/library/build.gradle +++ /dev/null @@ -1,190 +0,0 @@ -// Gradle script to build the "library" subproject of j-ogg-all - -plugins { - id 'checkstyle' // to analyze Java sourcecode for style violations - id 'java-library' // to build JVM libraries - id 'maven-publish' // to publish artifacts to Maven repositories - id 'signing' // to sign artifacts for publication -} - -ext { - artifact = 'j-ogg-all' - baseName = "${artifact}-${rootProject.ext.version}" // for artifacts -} - -java { - sourceCompatibility = JavaVersion.VERSION_1_7 - targetCompatibility = JavaVersion.VERSION_1_8 -} - -// Incorporate all the classes and resources of the j-ogg-vorbis library: -sourceSets.main { - java.srcDir '../vorbis/src/main/java' - resources.srcDir '../vorbis/src/main/resources' -} - -dependencies { - implementation(libs.jmf) -} - -checkstyle { - toolVersion libs.versions.checkstyle.get() -} - -tasks.withType(JavaCompile).configureEach { // Java compile-time options: - options.compilerArgs << '-Xdiags:verbose' - if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_14)) { - // Suppress warnings that source value 7 is obsolete. - options.compilerArgs << '-Xlint:-options' - } - //options.compilerArgs << '-Xlint:unchecked' - options.deprecation = true // to provide detailed deprecation warnings - options.encoding = 'UTF-8' - if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_1_10)) { - options.release = 8 - } -} - -javadoc { - // Disable doclint for JDK8+. - if (JavaVersion.current().isJava8Compatible()) { - options.addStringOption('Xdoclint:none', '-quiet') - } -} - -// Register publishing tasks: - -tasks.register('install') { - dependsOn 'publishMavenPublicationToMavenLocal' - description 'Installs Maven artifacts to the local repository.' -} -tasks.register('release') { - dependsOn 'publishMavenPublicationToOSSRHRepository' - description 'Stages Maven artifacts to Sonatype OSSRH.' -} - -// Register custom tasks for creating source/javadoc JARs: - -tasks.register('javadocJar', Jar) { - archiveClassifier = 'javadoc' - dependsOn 'javadoc' - description 'Creates a JAR of javadoc.' - from javadoc.destinationDir -} - -tasks.register('sourcesJar', Jar) { - archiveClassifier = 'sources' - description 'Creates a JAR of Java sourcecode.' - from sourceSets.main.allJava // default is ".allSource", which includes resources -} - -jar { - archiveBaseName = project.ext.baseName - doLast { - println "using Java ${JavaVersion.current()} (${System.getProperty("java.vendor")})" - } - manifest { - attributes 'Created-By': "${JavaVersion.current()} (${System.getProperty("java.vendor")})" - } -} -javadocJar { archiveBaseName = project.ext.baseName } -sourcesJar { archiveBaseName = project.ext.baseName } - -assemble.dependsOn('module', 'moduleAsc', 'pom', 'pomAsc') -tasks.register('module', Copy) { - dependsOn 'generateMetadataFileForMavenPublication' - description 'Copies the module metadata to build/libs.' - from "${buildDir}/publications/maven/module.json" - into "${buildDir}/libs" - rename 'module.json', project.ext.baseName + '.module' -} -tasks.register('moduleAsc', Copy) { - dependsOn 'signMavenPublication' - description 'Copies the signature of the module metadata to build/libs.' - from "${buildDir}/publications/maven/module.json.asc" - into "${buildDir}/libs" - rename 'module.json.asc', project.ext.baseName + '.module.asc' -} -tasks.register('pom', Copy) { - dependsOn 'generatePomFileForMavenPublication' - description 'Copies the Maven POM to build/libs.' - from "${buildDir}/publications/maven/pom-default.xml" - into "${buildDir}/libs" - rename 'pom-default.xml', project.ext.baseName + '.pom' -} -tasks.register('pomAsc', Copy) { - dependsOn 'signMavenPublication' - description 'Copies the signature of the Maven POM to build/libs.' - from "${buildDir}/publications/maven/pom-default.xml.asc" - into "${buildDir}/libs" - rename 'pom-default.xml.asc', project.ext.baseName + '.pom.asc' -} - -publishing { - publications { - maven(MavenPublication) { - artifact javadocJar - artifact sourcesJar - artifactId artifact - from components.java - groupId rootProject.ext.group - pom { - description = 'J-Ogg is a collection of Java libraries for reading Ogg files and decoding different contained formats.' - developers { - developer { - name = 'Tor-Einar Jarnbjo' - } - } - inceptionYear = '2002' - licenses { - license { - distribution = 'repo' - name = 'Free and commercial use, modification and redistribution with attribution.' - url = rootProject.ext.websiteUrl + '/blob/master/LICENSE' - } - } - name = rootProject.ext.group + ':' + artifact - scm { - connection = 'scm:git:git://github.com/stephengold/j-ogg-all.git' - developerConnection = 'scm:git:ssh://github.com:stephengold/j-ogg-all.git' - url = rootProject.ext.websiteUrl + '/tree/master' - } - url = rootProject.ext.websiteUrl - } - version rootProject.ext.version - } - } - // Staging to OSSRH relies on the existence of 2 properties - // (ossrhUsername and ossrhPassword) - // which should be stored in ~/.gradle/gradle.properties - repositories { - maven { - credentials { - username = project.hasProperty('ossrhUsername') ? ossrhUsername : 'Unknown user' - password = project.hasProperty('ossrhPassword') ? ossrhPassword : 'Unknown password' - } - name = 'OSSRH' - url = 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2' - } - } -} -generateMetadataFileForMavenPublication.dependsOn('pom') -publishMavenPublicationToMavenLocal.dependsOn('assemble') -publishMavenPublicationToMavenLocal.doLast { - println 'installed locally as ' + project.ext.baseName -} -publishMavenPublicationToOSSRHRepository.dependsOn('assemble') - -// Register signing tasks: - -// Signing relies on the existence of 3 properties -// (signing.keyId, signing.password, and signing.secretKeyRingFile) -// which should be stored in ~/.gradle/gradle.properties - -signing { - sign publishing.publications.maven -} -tasks.withType(Sign) { - onlyIf { rootProject.hasProperty('signing.keyId') } -} -signMavenPublication.dependsOn('module') diff --git a/library/build.gradle.kts b/library/build.gradle.kts new file mode 100644 index 0000000..4e3acf7 --- /dev/null +++ b/library/build.gradle.kts @@ -0,0 +1,179 @@ +// Gradle script to build the "library" subproject of j-ogg-all + +plugins { + `checkstyle` // to analyze Java sourcecode for style violations + `java-library` // to build JVM libraries + `maven-publish` // to publish artifacts to Maven repositories + `signing` // to sign artifacts for publication +} + +val group = "com.github.stephengold" +val artifact = "j-ogg-all" +val libraryVersion = rootProject.ext["version"] as String +val baseName = "${artifact}-${libraryVersion}" // for artifacts +val javaVendor = System.getProperty("java.vendor") +val javaVersion = JavaVersion.current() +val websiteUrl = "https://github.com/stephengold/j-ogg-all" + +java { + sourceCompatibility = JavaVersion.VERSION_1_7 + targetCompatibility = JavaVersion.VERSION_1_8 +} + +// Incorporate all the classes and resources of the j-ogg-vorbis library: +sourceSets.main { + java.srcDir("../vorbis/src/main/java") + resources.srcDir("../vorbis/src/main/resources") +} + +dependencies { + implementation(libs.jmf) +} + +checkstyle { + toolVersion = libs.versions.checkstyle.get() +} + +tasks.withType().all { // Java compile-time options: + options.compilerArgs.add("-Xdiags:verbose") + if (javaVersion.isCompatibleWith(JavaVersion.VERSION_14)) { + // Suppress warnings that source value 7 is obsolete. + options.compilerArgs.add("-Xlint:-options") + } + options.compilerArgs.add("-Xlint:unchecked") + options.setDeprecation(true) // to provide detailed deprecation warnings + options.encoding = "UTF-8" + if (javaVersion.isCompatibleWith(JavaVersion.VERSION_1_10)) { + options.release = 8 + } +} + +// TODO Disable doclint for JDK8+ + +// Register publishing tasks: + +tasks.register("install") { + dependsOn("publishMavenPublicationToMavenLocal") + description = "Installs the Maven artifacts to the local repository." +} +tasks.register("release") { + dependsOn("publishMavenPublicationToOSSRHRepository") + description = "Stages the Maven artifacts to Sonatype OSSRH." +} + +tasks.jar { + archiveBaseName.set(baseName) + doLast { + println("built using Java $javaVersion ($javaVendor)") + } + manifest { + attributes["Created-By"] = "$javaVersion ($javaVendor)" + } +} + +java.withJavadocJar() +tasks.named("javadocJar") { archiveBaseName.set(baseName) } +tasks.register("sourcesJar") { + archiveBaseName.set(baseName) + archiveClassifier.set("sources") + description = "Creates a JAR of Java sourcecode." + from(sourceSets.main.get().java) // default is ".allSource", which includes resources +} + +tasks.named("assemble") { dependsOn("module", "moduleAsc", "pom", "pomAsc") } +tasks.register("module") { + dependsOn("generateMetadataFileForMavenPublication") + description = "Copies the module metadata to build/libs." + from("build/publications/maven/module.json") + into("build/libs") + rename("module.json", baseName + ".module") +} +tasks.register("moduleAsc") { + dependsOn("signMavenPublication") + description = "Copies the signature of the module metadata to build/libs." + from("build/publications/maven/module.json.asc") + into("build/libs") + rename("module.json.asc", baseName + ".module.asc") +} +tasks.register("pom") { + dependsOn("generatePomFileForMavenPublication") + description = "Copies the Maven POM to build/libs." + from("build/publications/maven/pom-default.xml") + into("build/libs") + rename("pom-default.xml", baseName + ".pom") +} +tasks.register("pomAsc") { + dependsOn("signMavenPublication") + description = "Copies the signature of the Maven POM to build/libs." + from("build/publications/maven/pom-default.xml.asc") + into("build/libs") + rename("pom-default.xml.asc", baseName + ".pom.asc") +} + +publishing { + publications { + create("maven") { + artifact(tasks.named("sourcesJar")) + artifactId = artifact + from(components["java"]) + groupId = group + pom { + description = "J-Ogg is a collection of Java libraries for reading Ogg files and decoding different contained formats." + developers { + developer { + name = "Tor-Einar Jarnbjo" + } + } + inceptionYear = "2002" + licenses { + license { + distribution = "repo" + name = "Free and commercial use, modification and redistribution with attribution." + url = websiteUrl + "/blob/master/LICENSE" + } + } + name = "${group}:${artifact}" + scm { + connection = "scm:git:git://github.com/stephengold/j-ogg-all.git" + developerConnection = "scm:git:ssh://github.com:stephengold/j-ogg-all.git" + url = websiteUrl + "/tree/master" + } + url = websiteUrl + } + version = libraryVersion + } + } + // Staging to OSSRH relies on the existence of 2 properties + // (ossrhUsername and ossrhPassword) + // which should be stored in ~/.gradle/gradle.properties + repositories { + maven { + credentials { + username = if (hasProperty("ossrhUsername")) property("ossrhUsername") as String else "Unknown user" + password = if (hasProperty("ossrhPassword")) property("ossrhPassword") as String else "Unknown password" + } + name = "OSSRH" + url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2") + } + } +} +tasks.named("generateMetadataFileForMavenPublication") { dependsOn("pom") } +tasks.named("publishMavenPublicationToMavenLocal") { + dependsOn("assemble") + doLast { println("installed locally as " + baseName) } +} +tasks.named("publishMavenPublicationToOSSRHRepository") { dependsOn("assemble") } + +// Register signing tasks: + +// Signing relies on the existence of 3 properties +// (signing.keyId, signing.password, and signing.secretKeyRingFile) +// which should be stored in ~/.gradle/gradle.properties + +signing { + sign(publishing.publications["maven"]) +} +tasks.withType().all { + onlyIf { project.hasProperty("signing.keyId") } +} +tasks.named("signMavenPublication") { dependsOn("module") } diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 6f21f47..0000000 --- a/settings.gradle +++ /dev/null @@ -1,29 +0,0 @@ -// global build settings shared by all j-ogg-all subprojects - -rootProject.name = 'j-ogg-all' - -dependencyResolutionManagement { - repositories { - //mavenLocal() // to find libraries installed locally - mavenCentral() // to find libraries released to the Maven Central repository - //maven { url 'https://s01.oss.sonatype.org/content/groups/staging' } // to find libraries staged but not yet released - //maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots' } // to find public snapshots of libraries - } -} - -/* - * Enumerate subdirectories in the project's root directory that contain a - * "build.gradle" file. Any subdirectory that contains a "build.gradle" file is - * automatically included as a subproject. - */ -def subDirs = rootDir.listFiles( - new FileFilter() { - boolean accept(File file) { - return file.isDirectory() && new File(file, 'build.gradle').isFile() - } - } -) - -subDirs.each { File sub -> - include sub.name -} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..ecfc105 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,16 @@ +// global build settings shared by all j-ogg-all subprojects + +rootProject.name = "j-ogg-all" + +dependencyResolutionManagement { + repositories { + //mavenLocal() // to find libraries installed locally + mavenCentral() // to find libraries released to the Maven Central repository + //maven { url = uri("https://s01.oss.sonatype.org/content/groups/staging") } // to find libraries staged but not yet released + //maven { url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots") } // to find public snapshots of libraries + } +} + +// subprojects: +include("library") +include("vorbis") diff --git a/vorbis/build.gradle b/vorbis/build.gradle deleted file mode 100644 index a4105f8..0000000 --- a/vorbis/build.gradle +++ /dev/null @@ -1,180 +0,0 @@ -// Gradle script to build the "vorbis" subproject of j-ogg-all - -plugins { - id 'checkstyle' // to analyze Java sourcecode for style violations - id 'java-library' // to build JVM libraries - id 'maven-publish' // to publish artifacts to Maven repositories - id 'signing' // to sign artifacts for publication -} - -ext { - artifact = 'j-ogg-vorbis' - baseName = "${artifact}-${rootProject.ext.version}" // for artifacts -} - -java { - sourceCompatibility = JavaVersion.VERSION_1_7 - targetCompatibility = JavaVersion.VERSION_1_8 -} - -checkstyle { - toolVersion libs.versions.checkstyle.get() -} - -tasks.withType(JavaCompile).configureEach { // Java compile-time options: - options.compilerArgs << '-Xdiags:verbose' - if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_14)) { - // Suppress warnings that source value 7 is obsolete. - options.compilerArgs << '-Xlint:-options' - } - //options.compilerArgs << '-Xlint:unchecked' - options.deprecation = true // to provide detailed deprecation warnings - options.encoding = 'UTF-8' - if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_1_10)) { - options.release = 8 - } -} - -javadoc { - // Disable doclint for JDK8+. - if (JavaVersion.current().isJava8Compatible()) { - options.addStringOption('Xdoclint:none', '-quiet') - } -} - -// Register publishing tasks: - -tasks.register('install') { - dependsOn 'publishMavenPublicationToMavenLocal' - description 'Installs Maven artifacts to the local repository.' -} -tasks.register('release') { - dependsOn 'publishMavenPublicationToOSSRHRepository' - description 'Stages Maven artifacts to Sonatype OSSRH.' -} - -// Register custom tasks for creating source/javadoc JARs: - -tasks.register('javadocJar', Jar) { - archiveClassifier = 'javadoc' - dependsOn 'javadoc' - description 'Creates a JAR of javadoc.' - from javadoc.destinationDir -} - -tasks.register('sourcesJar', Jar) { - archiveClassifier = 'sources' - description 'Creates a JAR of Java sourcecode.' - from sourceSets.main.allJava // default is ".allSource", which includes resources -} - -jar { - archiveBaseName = project.ext.baseName - doLast { - println "using Java ${JavaVersion.current()} (${System.getProperty("java.vendor")})" - } - manifest { - attributes 'Created-By': "${JavaVersion.current()} (${System.getProperty("java.vendor")})" - } -} -javadocJar { archiveBaseName = project.ext.baseName } -sourcesJar { archiveBaseName = project.ext.baseName } - -assemble.dependsOn('module', 'moduleAsc', 'pom', 'pomAsc') -tasks.register('module', Copy) { - dependsOn 'generateMetadataFileForMavenPublication' - description 'Copies the module metadata to build/libs.' - from "${buildDir}/publications/maven/module.json" - into "${buildDir}/libs" - rename 'module.json', project.ext.baseName + '.module' -} -tasks.register('moduleAsc', Copy) { - dependsOn 'signMavenPublication' - description 'Copies the signature of the module metadata to build/libs.' - from "${buildDir}/publications/maven/module.json.asc" - into "${buildDir}/libs" - rename 'module.json.asc', project.ext.baseName + '.module.asc' -} -tasks.register('pom', Copy) { - dependsOn 'generatePomFileForMavenPublication' - description 'Copies the Maven POM to build/libs.' - from "${buildDir}/publications/maven/pom-default.xml" - into "${buildDir}/libs" - rename 'pom-default.xml', project.ext.baseName + '.pom' -} -tasks.register('pomAsc', Copy) { - dependsOn 'signMavenPublication' - description 'Copies the signature of the Maven POM to build/libs.' - from "${buildDir}/publications/maven/pom-default.xml.asc" - into "${buildDir}/libs" - rename 'pom-default.xml.asc', project.ext.baseName + '.pom.asc' -} - -publishing { - publications { - maven(MavenPublication) { - artifact javadocJar - artifact sourcesJar - artifactId artifact - from components.java - groupId rootProject.ext.group - pom { - description = 'Library for reading Ogg files and decoding the Vorbis audio format.' - developers { - developer { - name = 'Tor-Einar Jarnbjo' - } - } - inceptionYear = '2002' - licenses { - license { - distribution = 'repo' - name = 'Free and commercial use, modification and redistribution with attribution.' - url = rootProject.ext.websiteUrl + '/blob/master/LICENSE' - } - } - name = rootProject.ext.group + ':' + artifact - scm { - connection = 'scm:git:git://github.com/stephengold/j-ogg-all.git' - developerConnection = 'scm:git:ssh://github.com:stephengold/j-ogg-all.git' - url = rootProject.ext.websiteUrl + '/tree/master' - } - url = rootProject.ext.websiteUrl - } - version rootProject.ext.version - } - } - // Staging to OSSRH relies on the existence of 2 properties - // (ossrhUsername and ossrhPassword) - // which should be stored in ~/.gradle/gradle.properties - repositories { - maven { - credentials { - username = project.hasProperty('ossrhUsername') ? ossrhUsername : 'Unknown user' - password = project.hasProperty('ossrhPassword') ? ossrhPassword : 'Unknown password' - } - name = 'OSSRH' - url = 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2' - } - } -} -generateMetadataFileForMavenPublication.dependsOn('pom') -publishMavenPublicationToMavenLocal.dependsOn('assemble') -publishMavenPublicationToMavenLocal.doLast { - println 'installed locally as ' + project.ext.baseName -} -publishMavenPublicationToOSSRHRepository.dependsOn('assemble') - -// Register signing tasks: - -// Signing relies on the existence of 3 properties -// (signing.keyId, signing.password, and signing.secretKeyRingFile) -// which should be stored in ~/.gradle/gradle.properties - -signing { - sign publishing.publications.maven -} -tasks.withType(Sign) { - onlyIf { rootProject.hasProperty('signing.keyId') } -} -signMavenPublication.dependsOn('module') diff --git a/vorbis/build.gradle.kts b/vorbis/build.gradle.kts new file mode 100644 index 0000000..dcd51c4 --- /dev/null +++ b/vorbis/build.gradle.kts @@ -0,0 +1,169 @@ +// Gradle script to build the "vorbis" subproject of j-ogg-all + +plugins { + `checkstyle` // to analyze Java sourcecode for style violations + `java-library` // to build JVM libraries + `maven-publish` // to publish artifacts to Maven repositories + `signing` // to sign artifacts for publication +} + +val group = "com.github.stephengold" +val artifact = "j-ogg-vorbis" +val libraryVersion = rootProject.ext["version"] as String +val baseName = "${artifact}-${libraryVersion}" // for artifacts +val javaVendor = System.getProperty("java.vendor") +val javaVersion = JavaVersion.current() +val websiteUrl = "https://github.com/stephengold/j-ogg-all" + +java { + sourceCompatibility = JavaVersion.VERSION_1_7 + targetCompatibility = JavaVersion.VERSION_1_8 +} + +checkstyle { + toolVersion = libs.versions.checkstyle.get() +} + +tasks.withType().all { // Java compile-time options: + options.compilerArgs.add("-Xdiags:verbose") + if (javaVersion.isCompatibleWith(JavaVersion.VERSION_14)) { + // Suppress warnings that source value 7 is obsolete. + options.compilerArgs.add("-Xlint:-options") + } + options.compilerArgs.add("-Xlint:unchecked") + options.setDeprecation(true) // to provide detailed deprecation warnings + options.encoding = "UTF-8" + if (javaVersion.isCompatibleWith(JavaVersion.VERSION_1_10)) { + options.release = 8 + } +} + +// TODO Disable doclint for JDK8+ + +// Register publishing tasks: + +tasks.register("install") { + dependsOn("publishMavenPublicationToMavenLocal") + description = "Installs the Maven artifacts to the local repository." +} +tasks.register("release") { + dependsOn("publishMavenPublicationToOSSRHRepository") + description = "Stages the Maven artifacts to Sonatype OSSRH." +} + +tasks.jar { + archiveBaseName.set(baseName) + doLast { + println("built using Java $javaVersion ($javaVendor)") + } + manifest { + attributes["Created-By"] = "$javaVersion ($javaVendor)" + } +} + +java.withJavadocJar() +tasks.named("javadocJar") { archiveBaseName.set(baseName) } +tasks.register("sourcesJar") { + archiveBaseName.set(baseName) + archiveClassifier.set("sources") + description = "Creates a JAR of Java sourcecode." + from(sourceSets.main.get().java) // default is ".allSource", which includes resources +} + +tasks.named("assemble") { dependsOn("module", "moduleAsc", "pom", "pomAsc") } +tasks.register("module") { + dependsOn("generateMetadataFileForMavenPublication") + description = "Copies the module metadata to build/libs." + from("build/publications/maven/module.json") + into("build/libs") + rename("module.json", baseName + ".module") +} +tasks.register("moduleAsc") { + dependsOn("signMavenPublication") + description = "Copies the signature of the module metadata to build/libs." + from("build/publications/maven/module.json.asc") + into("build/libs") + rename("module.json.asc", baseName + ".module.asc") +} +tasks.register("pom") { + dependsOn("generatePomFileForMavenPublication") + description = "Copies the Maven POM to build/libs." + from("build/publications/maven/pom-default.xml") + into("build/libs") + rename("pom-default.xml", baseName + ".pom") +} +tasks.register("pomAsc") { + dependsOn("signMavenPublication") + description = "Copies the signature of the Maven POM to build/libs." + from("build/publications/maven/pom-default.xml.asc") + into("build/libs") + rename("pom-default.xml.asc", baseName + ".pom.asc") +} + +publishing { + publications { + create("maven") { + artifact(tasks.named("sourcesJar")) + artifactId = artifact + from(components["java"]) + groupId = group + pom { + description = "Library for reading Ogg files and decoding the Vorbis audio format." + developers { + developer { + name = "Tor-Einar Jarnbjo" + } + } + inceptionYear = "2002" + licenses { + license { + distribution = "repo" + name = "Free and commercial use, modification and redistribution with attribution." + url = websiteUrl + "/blob/master/LICENSE" + } + } + name = "${group}:${artifact}" + scm { + connection = "scm:git:git://github.com/stephengold/j-ogg-all.git" + developerConnection = "scm:git:ssh://github.com:stephengold/j-ogg-all.git" + url = websiteUrl + "/tree/master" + } + url = websiteUrl + } + version = libraryVersion + } + } + // Staging to OSSRH relies on the existence of 2 properties + // (ossrhUsername and ossrhPassword) + // which should be stored in ~/.gradle/gradle.properties + repositories { + maven { + credentials { + username = if (hasProperty("ossrhUsername")) property("ossrhUsername") as String else "Unknown user" + password = if (hasProperty("ossrhPassword")) property("ossrhPassword") as String else "Unknown password" + } + name = "OSSRH" + url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2") + } + } +} +tasks.named("generateMetadataFileForMavenPublication") { dependsOn("pom") } +tasks.named("publishMavenPublicationToMavenLocal") { + dependsOn("assemble") + doLast { println("installed locally as " + baseName) } +} +tasks.named("publishMavenPublicationToOSSRHRepository") { dependsOn("assemble") } + +// Register signing tasks: + +// Signing relies on the existence of 3 properties +// (signing.keyId, signing.password, and signing.secretKeyRingFile) +// which should be stored in ~/.gradle/gradle.properties + +signing { + sign(publishing.publications["maven"]) +} +tasks.withType().all { + onlyIf { project.hasProperty("signing.keyId") } +} +tasks.named("signMavenPublication") { dependsOn("module") }