Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,4 @@ jobs:
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.GPG_KEY_PASSPHRASE }}
MAVEN_CENTRAL_TOKEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_TOKEN_USERNAME }}
MAVEN_CENTRAL_TOKEN_PASSWORD: ${{ secrets.MAVEN_CENTRAL_TOKEN_PASSWORD }}
run: ./gradlew signArchives uploadArchives -Pversion=$SNAPSHOT_VERSION -PossrhUsername=${MAVEN_CENTRAL_TOKEN_USERNAME} -PossrhPassword=${MAVEN_CENTRAL_TOKEN_PASSWORD} -Psign=true

run: ./gradlew publish -Pversion=$SNAPSHOT_VERSION -PossrhUsername=${MAVEN_CENTRAL_TOKEN_USERNAME} -PossrhPassword=${MAVEN_CENTRAL_TOKEN_PASSWORD} -Psign=true
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
MAVEN_CENTRAL_TOKEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_TOKEN_USERNAME }}
MAVEN_CENTRAL_TOKEN_PASSWORD: ${{ secrets.MAVEN_CENTRAL_TOKEN_PASSWORD }}
RELEASE_VERSION: ${{ steps.tag_version_dry_run.outputs.tag }}
run: ./gradlew -Pversion=$RELEASE_VERSION signArchives uploadArchives -PossrhUsername=${MAVEN_CENTRAL_TOKEN_USERNAME} -PossrhPassword=${MAVEN_CENTRAL_TOKEN_PASSWORD} -Psign=true
run: ./gradlew -Pversion=$RELEASE_VERSION publish -PossrhUsername=${MAVEN_CENTRAL_TOKEN_USERNAME} -PossrhPassword=${MAVEN_CENTRAL_TOKEN_PASSWORD} -Psign=true
- name: Close & Release Staging Repository
env:
MAVEN_CENTRAL_TOKEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_TOKEN_USERNAME }}
Expand All @@ -55,4 +55,4 @@ jobs:
uses: softprops/action-gh-release@v1
with:
body: ${{steps.github_release.outputs.changelog}}
tag_name: ${{ steps.tag_version.outputs.tag }}
tag_name: ${{ steps.tag_version.outputs.tag }}
11 changes: 4 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ Gradle release plugin is not currently working so this is a manual process at th

```
gpg --import private.key
cd ~/.gnupg
gpg -k
gpg --export-secret-key YOUR_KEY_ID > ~/.gnupg/secring.gpg
```

## Preparing
Expand All @@ -62,13 +60,12 @@ gpg --export-secret-key YOUR_KEY_ID > ~/.gnupg/secring.gpg
```
export SONAR_USERNAME=?
export SONAR_PASSWORD=?
export GPG_KEY_ID=?
export GPG_KEY_PASSPHRASE=?
export PATH_TO_SECRING_GPG=~/.gnupg/secring.gpg
export ORG_GRADLE_PROJECT_signingKey="$(cat private.key)"
export ORG_GRADLE_PROJECT_signingPassword=?

# I found shadowed classes are not included if you don't separate the gradle operations
./gradlew clean shadowJar
./gradlew signArchives uploadArchives -PossrhUsername=${SONAR_USERNAME} -PossrhPassword=${SONAR_PASSWORD} -Psigning.keyId=${GPG_KEY_ID} -Psigning.password=${GPG_KEY_PASSPHRASE} -Psigning.secretKeyRingFile=${PATH_TO_SECRING_GPG}
./gradlew publish -PossrhUsername=${SONAR_USERNAME} -PossrhPassword=${SONAR_PASSWORD} -Psign=true
```

## Releasing [Full Tutorial](https://central.sonatype.org/pages/ossrh-guide.html)
Expand All @@ -86,4 +83,4 @@ export PATH_TO_SECRING_GPG=~/.gnupg/secring.gpg

1. Checkout master branch
1. Increment version number in `gradle.properties`
1. Create pull request for merge
1. Create pull request for merge
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ testImplementation 'io.github.origin-energy:java-snapshot-testing-plugin-jackson
testImplementation 'com.fasterxml.jackson.core:jackson-core:2.11.3'
testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.11.3'

// For Jackson 3 use the dedicated plugin and serializer classes instead
testImplementation 'io.github.origin-energy:java-snapshot-testing-plugin-jackson3:4.+'
testImplementation 'tools.jackson.core:jackson-core:3.1.0'
testImplementation 'tools.jackson.core:jackson-databind:3.1.0'

// Optional: If you want Jackson to serialize Java 8 date/time types or Optionals you should also add the following dependencies
testRuntimeOnly 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.11.3'
testRuntimeOnly 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.11.3'
Expand All @@ -51,6 +56,10 @@ serializer=au.com.origin.snapshots.serializers.v1.ToStringSnapshotSerializer
serializer.base64=au.com.origin.snapshots.serializers.v1.Base64SnapshotSerializer
serializer.json=au.com.origin.snapshots.jackson.serializers.v1.JacksonSnapshotSerializer
serializer.orderedJson=au.com.origin.snapshots.jackson.serializers.v1.DeterministicJacksonSnapshotSerializer

# Jackson 3 alternative
Comment thread
jackmatt2 marked this conversation as resolved.
Outdated
# serializer.json=au.com.origin.snapshots.jackson3.serializers.v1.Jackson3SnapshotSerializer
# serializer.orderedJson=au.com.origin.snapshots.jackson3.serializers.v1.DeterministicJackson3SnapshotSerializer
comparator=au.com.origin.snapshots.comparators.v1.PlainTextEqualsComparator
reporters=au.com.origin.snapshots.reporters.v1.PlainTextSnapshotReporter
snapshot-dir=__snapshots__
Expand Down Expand Up @@ -151,14 +160,18 @@ We currently support:
Plugins

- [Jackson for JSON serialization](https://search.maven.org/search?q=a:java-snapshot-testing-plugin-jackson)
- [Jackson 3 for JSON serialization](https://search.maven.org/search?q=a:java-snapshot-testing-plugin-jackson3)
- You need jackson on your classpath (Gradle example)
```groovy
// Required java-snapshot-testing peer dependencies
// Jackson 2 plugin
testImplementation 'io.github.origin-energy:java-snapshot-testing-plugin-jackson:4.+'
testImplementation 'com.fasterxml.jackson.core:jackson-core:2.11.3'
testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.11.3'
// Optional java-snapshot-testing peer dependencies
testRuntimeOnly 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.11.3'
testRuntimeOnly 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.11.3'

// Jackson 3 plugin
testImplementation 'io.github.origin-energy:java-snapshot-testing-plugin-jackson3:4.+'
testImplementation 'tools.jackson.core:jackson-core:3.1.0'
testImplementation 'tools.jackson.core:jackson-databind:3.1.0'
```

## How does it work?
Expand Down
101 changes: 80 additions & 21 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,48 +1,107 @@
import org.gradle.api.tasks.compile.GroovyCompile
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.api.tasks.javadoc.Javadoc
import org.gradle.api.tasks.testing.Test

plugins {
id 'net.researchgate.release' version '2.6.0' apply false
id 'com.github.johnrengelman.shadow' version '5.2.0' apply false
id 'com.gradleup.shadow' version '9.3.2' apply false
id 'io.codearte.nexus-staging' version '0.22.0'
id "com.diffplug.spotless" version "6.11.0" apply false
id 'com.diffplug.spotless' version '8.4.0' apply false
}

ext {
junit5Version = '5.10.2'
lombokVersion = '1.18.20'
slf4jVersion = '2.0.0-alpha0'
assertjVersion = '3.11.1'
}

subprojects { subproject ->
// FIXME this plugin is currently not working for multi-module projects even when defined at the top level only
// Will need to release and TAG manually for now
subproject.apply plugin: 'net.researchgate.release'
subproject.apply plugin: 'java-library'
subproject.apply plugin: 'com.github.johnrengelman.shadow'
subproject.apply plugin: 'com.gradleup.shadow'
subproject.apply plugin: 'maven-publish'

sourceCompatibility = '1.8'
targetCompatibility = '1.8'
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

repositories {
mavenCentral()
}

if (subproject.name == 'java-snapshot-testing-plugin-jackson3') {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this long if else needed as it wasn't required previously? Will the code work without it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Jackson 3 module needs Java 17 because Jackson 3 artifacts require Java 17.
The long root if/else is not needed the default can stay Java 11 and Jackson 3 can override locally.

tasks.withType(JavaCompile).configureEach {
javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(17)
}
}

tasks.withType(Javadoc).configureEach {
javadocTool = javaToolchains.javadocToolFor {
languageVersion = JavaLanguageVersion.of(17)
}
}

tasks.withType(Test).configureEach {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(17)
}
}
} else {
tasks.withType(JavaCompile).configureEach {
javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(11)
}
}

tasks.withType(Javadoc).configureEach {
javadocTool = javaToolchains.javadocToolFor {
languageVersion = JavaLanguageVersion.of(11)
}
}

tasks.withType(Test).configureEach {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(11)
}
}

tasks.withType(GroovyCompile).configureEach {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(11)
}
}
}

shadowJar {
classifier = ''
relocate 'org.assertj', 'shadow.org.assertj'
relocate 'org.opentest4j', 'shadow.org.opentest4j'
exclude "module-info.class"
archiveClassifier = ''
if (subproject.name != 'java-snapshot-testing-plugin-jackson3') {
Comment thread
jackmatt2 marked this conversation as resolved.
Outdated
relocate 'org.assertj', 'shadow.org.assertj'
relocate 'org.opentest4j', 'shadow.org.opentest4j'
}
exclude 'module-info.class'
}

jar {
archiveClassifier = 'thin'
}

dependencies {
// Lombok
compileOnly 'org.projectlombok:lombok:1.18.20'
annotationProcessor 'org.projectlombok:lombok:1.18.20'
testCompileOnly 'org.projectlombok:lombok:1.18.20'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.20'
Comment thread
jackmatt2 marked this conversation as resolved.

// Logging implementation
compileOnly 'org.slf4j:slf4j-api:2.0.0-alpha0'
compileOnly "org.projectlombok:lombok:${project.lombokVersion}"
annotationProcessor "org.projectlombok:lombok:${project.lombokVersion}"
testCompileOnly "org.projectlombok:lombok:${project.lombokVersion}"
testAnnotationProcessor "org.projectlombok:lombok:${project.lombokVersion}"

compileOnly "org.slf4j:slf4j-api:${project.slf4jVersion}"
}

// Add verbose logging for Github Actions
Comment thread
jackmatt2 marked this conversation as resolved.
test {
testLogging {
events "passed", "skipped", "failed"
exceptionFormat "full"
}
}
}
}
9 changes: 9 additions & 0 deletions gradle/junit5.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dependencies {
testImplementation platform("org.junit:junit-bom:${project.junit5Version}")
testImplementation 'org.junit.jupiter:junit-jupiter'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

test {
useJUnitPlatform()
}
117 changes: 59 additions & 58 deletions gradle/publishing.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,81 +8,82 @@ task sourcesJar(type: Jar) {
from sourceSets.main.allSource
}

artifacts {
archives javadocJar, sourcesJar
}

apply plugin: 'net.researchgate.release'

// Sign for maven central deployment
publishing {
publications.withType(MavenPublication).configureEach {
artifact javadocJar
artifact sourcesJar

pom {
name = 'java-snapsho-testing'
Comment thread
jackmatt2 marked this conversation as resolved.
Outdated
description = 'Snapshot Testing for Java'
url = 'https://github.com/origin-energy/java-snapshot-testing'

scm {
connection = 'scm:git:https://github.com/origin-energy/java-snapshot-testing'
url = 'https://github.com/origin-energy/java-snapshot-testing'
}

licenses {
license {
name = 'MIT License'
url = 'http://www.opensource.org/licenses/mit-license.php'
}
}

developers {
developer {
id = 'jack.matthews'
name = 'Jack Matthews'
email = 'jack.matthews@origin.com.au'
}
}

withXml {
def pomNode = asNode()
pomNode.children().removeAll { child -> child instanceof Node && child.name() == 'dependencies' }
}
}
}
}

if (project.hasProperty("sign")) {
apply plugin: 'signing'
signing {
def signingKey = findProperty("signingKey")
def signingPassword = findProperty("signingPassword")
useInMemoryPgpKeys(signingKey, signingPassword)
sign configurations.archives
}
}

// previously the plugin was using the `build` version which did not include the shadowed dependencies
signArchives.dependsOn 'shadowJar'
afterEvaluate {
if (project.hasProperty("sign")) {
signing {
sign publishing.publications
Comment thread
jackmatt2 marked this conversation as resolved.
}
}
}

// Maven Central Publishing
if (project.hasProperty("ossrhUsername") && project.hasProperty("ossrhPassword")) {
apply plugin: 'maven'
publishing {
repositories {
maven {
name = 'sonatype'
url = uri(project.version.toString().endsWith('-SNAPSHOT')
? 'https://oss.sonatype.org/content/repositories/snapshots/'
: 'https://oss.sonatype.org/service/local/staging/deploy/maven2/')
credentials {
username = project.property("ossrhUsername")
password = project.property("ossrhPassword")
}
}
}
}

nexusStaging {
username project.property("ossrhUsername")
password project.property("ossrhPassword")
packageGroup 'io.github.origin-energy'
}

uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}

snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}

pom.project {
name 'java-snapsho-testing'
packaging 'jar'
description 'Snapshot Testing for Java'
url 'https://github.com/origin-energy/java-snapshot-testing'
scm {
connection 'scm:git:https://github.com/origin-energy/java-snapshot-testing'
url 'https://github.com/origin-energy/java-snapshot-testing'
}

licenses {
license {
name 'MIT License'
url 'http://www.opensource.org/licenses/mit-license.php'
}
}

developers {
developer {
id 'jack.matthews'
name 'Jack Matthews'
email 'jack.matthews@origin.com.au'
}
}
}

// We clear out all the dependencies because we have shadowed them inside the jar
pom.whenConfigured {
p -> p.dependencies = []
}
}
}
}
}

3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Fri Apr 17 09:29:12 CEST 2026
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading