Skip to content

Commit

Permalink
Merge branch 'fix/publishing' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg committed Dec 24, 2023
2 parents fbad911 + a932ccf commit c249baa
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
* Publish `selfie-lib-jvm` instead of just `selfie-lib` to Maven Central.

## [0.1.1] - 2023-12-24
* Initial release, take 2.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repositories {
}
group =.proj('maven_group', 'the maven group, recommend com.diffplug')
apply from: rootProject.file('gradle/spotless.gradle')
apply from: .file('base/changelog.gradle')
apply from: rootProject.file('gradle/changelog.gradle')
apply from: 干.file('base/sonatype.gradle')

// ./gradlew :dokkatooGeneratePublicationHtml
Expand Down
93 changes: 93 additions & 0 deletions gradle/changelog.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// no parameters needed, just apply `com.diffplug.spotless-changelog` on whichever project has
// CHANGELOG.md
//
// this script will look for the changelog tasks in either this project or the parent project,
// and then set the version from the spotless-changelog plugin. It will also hook the jar task
// (if present) to depend on changelogCheck, so that a jar will never get published with a bad
// changelog. Lastly, changelogBump will depend on a successful closeAndReleaseSonatypeStagingRepository.

def requireEnablePublishing(Task task) {
if (project.findProperty('enable_publishing') == 'true') {
return true
} else {
task.doFirst {
throw new Error("Cannot run " + task + " without specifying enable_publishing=true")
}
return false
}
}

def pubName() {
if (plugins.hasPlugin('java-gradle-plugin')) {
return 'PluginMaven'
} else if (plugins.hasPlugin('org.jetbrains.kotlin.multiplatform')) {
return 'Jvm'
} else {
return 'MavenJava'
}
}

if (tasks.names.contains('changelogCheck')) {
spotlessChangelog {
branch 'release'
appendDashSnapshotUnless_dashPrelease = true
}
// set the project version for POM, jar manifest, etc.
version = spotlessChangelog.versionNext
// ensures that nothing will be built if changelogPush will end up failing
afterEvaluate {
if (tasks.names.contains('jar')) {
tasks.named('jar').configure {
dependsOn tasks.named('changelogCheck')
}
}
// ensures that changelog bump and push only happens if the publish was successful
tasks.named('changelogBump').configure {
if (requireEnablePublishing(it)) {
if (plugins.hasPlugin('maven-publish')) {
if (plugins.hasPlugin('io.github.gradle-nexus.publish-plugin')) {
dependsOn "publish${pubName()}PublicationToSonatypeRepository"
// only the root project has closeSonatypeStagingRepository, and it finalizes all publishToSonatype tasks
// https://github.com/gradle-nexus/publish-plugin
dependsOn rootProject.tasks.named('closeAndReleaseSonatypeStagingRepository')
} else {
dependsOn "publishAllPublicationsToGitLabRepository"
}
}
// if we have a gradle plugin, we need to push it up to the plugin portal too
if (tasks.names.contains('publishPlugins')) {
dependsOn tasks.named('publishPlugins')
}
}
}
}
} else {
assert parent != null : 'If you apply this script to the root project, you must have plugin com.diffplug.spotless-changelog'
assert parent.tasks.names.contains('changelogCheck') : 'Neither this project nor its parent had the required plugin com.diffplug.spotless-changelog'

// same as above, but pull changelog stuff from the parent changelog
version = parent.spotlessChangelog.versionNext
def childProject = project;
afterEvaluate {
if (tasks.names.contains('jar')) {
tasks.named('jar').configure {
dependsOn parent.tasks.named('changelogCheck')
}
}
parent.tasks.named('changelogBump').configure {
if (requireEnablePublishing(it)) {
if (childProject.plugins.hasPlugin('maven-publish')) {
if (rootProject.plugins.hasPlugin('io.github.gradle-nexus.publish-plugin')) {
dependsOn childProject.tasks.named("publish${pubName()}PublicationToSonatypeRepository")
dependsOn rootProject.tasks.named('closeAndReleaseSonatypeStagingRepository')
} else {
dependsOn childProject.tasks.named("publishAllPublicationsToGitLabRepository")
}
}
if (childProject.tasks.names.contains('publishPlugins')) {
dependsOn childProject.tasks.named('publishPlugins')
}
}
}
}
}
2 changes: 1 addition & 1 deletion selfie-lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ext {
maven_desc = 'Core logic and parsing for Selfie'
}

apply from: .file('base/changelog.gradle')
apply from: rootProject.file('gradle/changelog.gradle')
apply from: rootProject.file('gradle/spotless.gradle')
kotlin {
jvm {
Expand Down
2 changes: 1 addition & 1 deletion selfie-runner-junit5/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ext {
maven_desc = 'JUnit 5 test runner for Selfie'
}

apply from: .file('base/changelog.gradle')
apply from: rootProject.file('gradle/changelog.gradle')
apply from: rootProject.file('gradle/spotless.gradle')
apply plugin: 'java-library'
dependencies {
Expand Down

0 comments on commit c249baa

Please sign in to comment.