From 36d0baed900dec7e4c74796f0419ac76d449bcfd Mon Sep 17 00:00:00 2001 From: Gerd Aschemann Date: Sun, 23 Jun 2024 23:07:02 +0200 Subject: [PATCH] Finalize build for Maven Central upload --- build.gradle | 65 +++++++++++++++- gradle.properties | 1 + htmlSanityCheck-core/build.gradle | 8 ++ htmlSanityCheck-gradle-plugin/build.gradle | 26 +++++++ src/docs/DevelopmentDocs.adoc | 10 +-- src/docs/development/publishing.adoc | 88 +++++++++++++++------- 6 files changed, 160 insertions(+), 38 deletions(-) diff --git a/build.gradle b/build.gradle index 461c9a88..623ed535 100644 --- a/build.gradle +++ b/build.gradle @@ -40,6 +40,22 @@ allprojects { } } +// tag::mavenBuildRepo[] +File baseBuildDir = file("${project.rootDir}/build") +File mavenBuildRepo = new File(baseBuildDir, "maven-repo") +// end::mavenBuildRepo[] + +// tag::artifactsZip[] +String artifactsZip = 'publish-to-maven-central.zip' +// end::artifactsZip[] + +task zipArtifacts(type: Zip) { + from mavenBuildRepo + exclude '**/maven-metadata.xml*' + archiveFileName.set(artifactsZip) + destinationDirectory.set(baseBuildDir) +} + configure(subprojects) { apply plugin: 'java' apply plugin: 'groovy' @@ -61,15 +77,56 @@ configure(subprojects) { toolchain { languageVersion = JavaLanguageVersion.of(8) } + withSourcesJar() } publishing { + publications.all { publication -> + if (publication instanceof MavenPublication) { + publication.pom { + name = project.name + description = project.description + url = "https://aim42.github.io/htmlSanityCheck/" + licenses { + license { + name = 'The Apache License, Version 2.0' + url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + } + } + developers { + developer { + id = 'gstarke' + name = 'Gernot Starke' + email = 'gs@gernotstarke.de' + } + developer { + id = 'ascheman' + name = 'Gerd Aschemann' + email = 'gerd@aschemann.net' + } + developer { + id = 'rdmueller' + name = 'Ralf D. Müller' + email = 'ralf.d.mueller@gmail.com' + } + developer { + id = 'ruhrotht' + name = 'Thomas Ruhroth' + email = 'Thomas.Ruhroth@msg.group' + } + } + scm { + connection = 'scm:git:git://github.com/aim42/htmlSanityCheck.git' + developerConnection = 'scm:git:ssh://github.com/aim42/htmlSanityCheck.git' + url = 'https://github.com/aim42/htmlSanityCheck' + } + } + } + } repositories { maven { name = 'myLocalRepositoryForFullIntegrationTests' - //noinspection GrDeprecatedAPIUsage - File baseDir = file(project.parent.buildDir) - url = new File(baseDir, "maven-repo") + url = mavenBuildRepo } mavenLocal() } @@ -91,7 +148,7 @@ configure(subprojects) { } def groovyVersion = libs.groovy.bom.get().version -def groovyVersionMajorMinor = groovyVersion.split('\\.')[0..1] .join('.') +def groovyVersionMajorMinor = groovyVersion.split('\\.')[0..1].join('.') tasks.named("dependencyUpdates").configure { gradleReleaseChannel = true diff --git a/gradle.properties b/gradle.properties index 81cafe4b..c634ee46 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,6 +3,7 @@ htmlSanityCheckVersion=2.0.0-SNAPSHOT # end::version[] group = org.aim42.htmlSanityCheck +description = HTML Sanity Check org.gradle.jvmargs=-Xmx2G org.gradle.parallel=true diff --git a/htmlSanityCheck-core/build.gradle b/htmlSanityCheck-core/build.gradle index b4916369..941e02fa 100644 --- a/htmlSanityCheck-core/build.gradle +++ b/htmlSanityCheck-core/build.gradle @@ -50,6 +50,14 @@ gitProperties { ] } +java { + withJavadocJar() +} + +javadoc { + options.addStringOption('Xdoclint:none', '-quiet') +} + publishing { publications { mavenJava(MavenPublication) { diff --git a/htmlSanityCheck-gradle-plugin/build.gradle b/htmlSanityCheck-gradle-plugin/build.gradle index 6032ec29..d45c9305 100755 --- a/htmlSanityCheck-gradle-plugin/build.gradle +++ b/htmlSanityCheck-gradle-plugin/build.gradle @@ -12,10 +12,36 @@ tasks.named('check') { } gradlePlugin { + website = 'https://aim42.github.io/htmlSanityCheck/' + vcsUrl = 'https://github.com/aim42/HtmlSanityCheck.git' plugins { htmlSanityCheck { id = 'org.aim42.htmlSanityCheck' implementationClass = 'org.aim42.htmlsanitycheck.HtmlSanityCheckPlugin' + displayName = 'Gradle HtmlSanityCheck Plugin' + description = project.description + } + } +} + +groovydoc { + source = sourceSets.main.groovy.srcDirs + classpath = configurations.compileClasspath +} + +task groovydocJar(type: Jar, dependsOn: groovydoc) { + archiveClassifier = 'javadoc' + from groovydoc.destinationDir +} + +artifacts { + archives groovydocJar +} + +publishing { + publications { + pluginMaven(MavenPublication) { + artifact groovydocJar } } } diff --git a/src/docs/DevelopmentDocs.adoc b/src/docs/DevelopmentDocs.adoc index b84bc612..3b3895d4 100644 --- a/src/docs/DevelopmentDocs.adoc +++ b/src/docs/DevelopmentDocs.adoc @@ -68,15 +68,9 @@ by making $MODULE_DIR$ your default. image:intellij-run-configuration.jpg[] -== Building the Plugin +== Building and Uploading the Plugin -=== Uploading / Publishing to Maven Central and Bintray - -t.b.c. - -=== Uploading to Gradle Plugin Repository -Currently we use the Gradle Plugin Repository to host the plugin - which is very simple -to configure for users. +Check out https://aim42.github.io/htmlSanityCheck/development/publishing.html[Publishing] (on the Development Docs Site) for further instructions. == Design Discussions diff --git a/src/docs/development/publishing.adoc b/src/docs/development/publishing.adoc index ae47bd5c..7915f112 100644 --- a/src/docs/development/publishing.adoc +++ b/src/docs/development/publishing.adoc @@ -1,39 +1,75 @@ :filename: development/publishing.adoc === Publishing kbd:htmlSC Releases -==== Automating the Upload of a Gradle Plugin -Puh - handling Bintray or JCenter is -https://java.dzone.com/articles/enjoy-bintray-and-use-it-pain[not funny]. - -==== Handling (Secret) Credentials -We use Etienne Studers awesome -https://github.com/etiennestuder/gradle-credentials-plugin[Gradle-Credentials plugin] -to allow automatic deployment to public portals (like Bintray, JCenter and/or Gradle-Plugin-Portal) -and keep the appropriate passwords/API-keys secret. - -Brief instructions below - for details see the -https://github.com/etiennestuder/gradle-credentials-plugin[credentials plugin] - -. integrate the plugin in the buildfile -. get the required credentials from the Bintray website (or wherever you want to publish artifacts) -. add the required credentials: +==== Background + +Our Gradle build stores all artifacts and their meta-data (POM + module files, +as well as their respective hashes and signatures) in a local Maven repository. +They are subject to integration tests. +Finally, they can be uploaded to Maven Central (as ZIP file). + +* The build stores these files to the root build directory. + -[source] +[source, groovy] +---- +include::../../../build.gradle[tag=mavenBuildRepo] ---- -> gradle addCredentials --key bintrayUserName --value -:addCredentials -BUILD SUCCESSFUL +* And it stores the ZIP file there as well ++ +[source, groovy] +---- +include::../../../build.gradle[tag=artifactsZip] +---- + +==== Publishing actions -> gradle addCredentials --key bintrayApiKey --value +Adjust version number:: +Set the version number in xref:../../../gradle.properties[] to the next value. + +Build / publish local:: +Generate artifacts and publish them to the local Maven repository for integration tests ++ +[source,bash,subs="callouts+"] ---- -. Within the buildfile you can now access these credentials as follows: +./gradlew clean integrationTests # <1> +---- +<1> This will implicitly call the task `publishAllPublicationsToMyLocalRepositoryForFullIntegrationTestsRepository` which pushes all required files for publication to the repository. + +Sign:: +Sign artifacts, POMs, and modules with GPG. + -[source] +[source,bash] ---- -// include these lines in your build.gradle: -println "Username : " + credentials.bintrayUserName -println "Bintray API Key : " + credentials.bintrayApiKey +for i in $(find build -name "*.jar" -o -name "*.pom" -o -name "*.module"); do \ + gpg --yes -ab ${i}; \ +done ---- ++ +[NOTE] +.Setup PGP / GnuPG +==== +Setting up PGP (or GnuPG) is out of scope for this document. +Please refer to the respective documentation. +==== + +Build ZIP:: +Create a ZIP-File from all artifacts, POMs, and modules, their hashes, and signatures. ++ +[source, bash] +---- +./gradlew zipArtifacts +---- + +Upload ZIP to Maven Central:: +Finally, upload the resulting ZIP file (manually) to Maven Central, +i.e., https://central.sonatype.com/publishing[Sonatype Central]. ++ +[CAUTION] +.Credentials needed +==== +You need respective credentials to upload files to Maven Central for the `org.aim42.htmlSanityCheck` namespace. +Talk to Gernot Starke to get these permissions. +====