Skip to content

Commit

Permalink
mavenCentral publishing fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg committed Dec 26, 2023
2 parents c249baa + 130ae60 commit 0ab29a1
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 12 deletions.
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ git_url=github.com/diffplug/selfie
maven_group=com.diffplug.selfie
javadoc_links=

ver_JUNIT_API=5.0.0
ver_JUNIT_USE=5.10.1
ver_JUNIT_PIONEER=2.1.0
ver_OKIO=3.6.0
Expand Down
101 changes: 101 additions & 0 deletions gradle/maven.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// 干.mustRunAfter('base/gradle-plugin')
// 干.mustRunAfter('base/changelog')

apply plugin: 'maven-publish'

def git_url =.proj('git_url', 'the git url with no protocol, e.g.: github.com/diffplug/blowdryer')
assert !git_url.startsWith('https://') : 'git_url should not start with https://'
assert !git_url.startsWith('http://') : 'git_url should not start with http://'

group =.proj('maven_group', 'the maven group, recommend com.diffplug')
def maven_artifact = project.name
def maven_name =.proj('maven_name', 'human-friendly name')
def maven_desc =.proj('maven_desc', 'human-friendly description')

def javadocLinks =.proj('javadoc_links', "space-delimited links, if you add '/package-list' to the urls you should get a package list").split()
def license =.proj('license', 'supported: [apache, confidential, lgpl-2.1]')

def license_name =.prop('base/maven', "${license}_name")
def license_url =.prop('base/maven', "${license}_url")
def license_comments =.prop('base/maven', "${license}_comments")

boolean isKMP = project.pluginManager.hasPlugin('org.jetbrains.kotlin.multiplatform')
if (!isKMP) {
java {
withJavadocJar()
withSourcesJar()
}

tasks.named('sourcesJar') {
dependsOn 'jar'
}

javadoc {
def makeLink = { url, text -> "<a href=\"${url}\" style=\"text-transform: none;\">${text}</a>" }
def javadocInfo = '<h2>' + makeLink("https://${git_url}", "${maven_artifact}:${version}") +
' by ' + makeLink('https://www.diffplug.com', 'DiffPlug') + '</h2>';
// Where it's possible to name parameters and methods clearly enough
// that javadoc is not necessary, why make the code bigger?
// Thus, no javadoc warnings.
options.addStringOption('Xdoclint:none', '-quiet')
// UTF-8!!! Thanks to: https://github.com/freefair/gradle-plugins/blob/6d6f5ff6036e7da1c329075a02c6452c0bb669be/maven-plugin/src/main/java/io/freefair/gradle/plugins/maven/javadoc/JavadocUtf8Plugin.java
options.charSet('UTF-8');
options.docEncoding('UTF-8');
options.setEncoding('UTF-8');
// setup the header
options.header javadocInfo
options.footer javadocInfo
// setup links
options.links(javadocLinks)
}
apply from: 干.file('helper/javadoc-view.gradle')
}

boolean isPlugin = plugins.hasPlugin('java-gradle-plugin')
publishing.publications.withType(MavenPublication) {
// KMP-aware artifactId
if (artifactId.endsWith('-jvm')) {
artifactId = maven_artifact + '-jvm'
// create javadoc manually to keep MavenCentral happy
def javadocJar = tasks.register('dokkaJavadoc', Jar.class) {
dependsOn('dokkatooGenerate')
archiveClassifier.set("javadoc")
from('build/dokka-module/html')
}
artifact javadocJar
} else if (artifactId.endsWith("-js")) {
artifactId = maven_artifact + '-js'
} else {
artifactId = maven_artifact
}
if (!isPlugin && !isKMP) {
from components.java
}
pom {
name = maven_name
description = maven_desc
url = "https://$git_url"
licenses {
// has to be it.license because of parameter license above
it.license {
// https://maven.apache.org/pom.html#Licenses
name = license_name
url = license_url
distribution = 'repo'
comments = license_comments
}
}
developers {
developer {
id = 'nedtwigg'
name = 'Ned Twigg'
email = '[email protected]'
}
}
scm {
connection = "scm:git:git://${git_url}.git"
developerConnection = "scm:git:ssh://${git_url}.git"
url = "https://$git_url"
}
}
}
2 changes: 1 addition & 1 deletion selfie-lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ tasks.create('test') {
}

// it all needs to get published and formatted
apply from: .file('base/maven.gradle')
apply from: rootProject.file('gradle/maven.gradle')
apply from: 干.file('base/sonatype.gradle')
13 changes: 3 additions & 10 deletions selfie-runner-junit5/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,8 @@ apply from: rootProject.file('gradle/spotless.gradle')
apply plugin: 'java-library'
dependencies {
api project(':selfie-lib')
// see if we can drop this down to 1.0.0
implementation 'org.junit.platform:junit-platform-launcher:1.10.1'
compileOnly "org.junit.jupiter:junit-jupiter-api:$ver_JUNIT_API"
// jsoup
compileOnly 'org.jsoup:jsoup:1.17.1'
testImplementation 'org.jsoup:jsoup:1.17.1'
// flexmark
compileOnly 'com.vladsch.flexmark:flexmark-html2md-converter:0.64.8'
testImplementation 'com.vladsch.flexmark:flexmark-html2md-converter:0.64.8'
implementation 'org.junit.platform:junit-platform-launcher:1.0.0'
compileOnly "org.junit.jupiter:junit-jupiter-api:5.0.0"

testImplementation "com.squareup.okio:okio:$ver_OKIO"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit5:$ver_KOTLIN_TEST"
Expand All @@ -38,5 +31,5 @@ test {
}

// it all needs to get published and formatted
apply from: .file('base/maven.gradle')
apply from: rootProject.file('gradle/maven.gradle')
apply from: 干.file('base/sonatype.gradle')

0 comments on commit 0ab29a1

Please sign in to comment.