Skip to content

Commit

Permalink
Finalize build for Maven Central upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ascheman committed Jun 23, 2024
1 parent e3e82ca commit 36d0bae
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 38 deletions.
65 changes: 61 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 = '[email protected]'
}
developer {
id = 'ascheman'
name = 'Gerd Aschemann'
email = '[email protected]'
}
developer {
id = 'rdmueller'
name = 'Ralf D. Müller'
email = '[email protected]'
}
developer {
id = 'ruhrotht'
name = 'Thomas Ruhroth'
email = '[email protected]'
}
}
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()
}
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions htmlSanityCheck-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ gitProperties {
]
}

java {
withJavadocJar()
}

javadoc {
options.addStringOption('Xdoclint:none', '-quiet')
}

publishing {
publications {
mavenJava(MavenPublication) {
Expand Down
26 changes: 26 additions & 0 deletions htmlSanityCheck-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
10 changes: 2 additions & 8 deletions src/docs/DevelopmentDocs.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
88 changes: 62 additions & 26 deletions src/docs/development/publishing.adoc
Original file line number Diff line number Diff line change
@@ -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 <your-Bintray-username>
: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 <some-long-key>
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.
====

0 comments on commit 36d0bae

Please sign in to comment.