From ed07004d48dd03474513194689de99132f25c46a Mon Sep 17 00:00:00 2001 From: Martin Skopp Date: Wed, 27 Oct 2021 12:08:58 +0200 Subject: [PATCH] Change release-policy: include required dependencies in published JAR --- .github/workflows/release.yml | 4 + README.md | 18 ++++- build.gradle | 145 ++++++++++++++++++++++++++++++---- 3 files changed, 147 insertions(+), 20 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2cad7be..78e85e9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,6 +5,10 @@ on: tags: - v* +env: + GITHUB_PACKAGES_ACCESS_USER: ${{ secrets.GH_PACKAGES_ACCESS_USER }} + GITHUB_PACKAGES_ACCESS_TOKEN: ${{ secrets.GH_PACKAGES_ACCESS_TOKEN }} + jobs: release: runs-on: ubuntu-latest diff --git a/README.md b/README.md index 490f329..919f7f2 100644 --- a/README.md +++ b/README.md @@ -64,8 +64,13 @@ and it can be also integrated into a Java project as a depencency via https://ji [gradle](https://gradle.org/): + repositories { + ... + maven { url 'https://jitpack.io' } + } + dependencies { - implementation('com.github.riege:one-record-converter:0.8.0') { transitive = false } + implementation 'com.github.riege:one-record-converter:0.9.0' } [maven](https://maven.apache.org): @@ -73,13 +78,18 @@ and it can be also integrated into a Java project as a depencency via https://ji com.github.riege one-record-converter - 0.8.0 + 0.9.0 See https://jitpack.io/#riege/one-record-converter for more details. - ### Java version +**Update for version 0.9 and above**: The one-record-converter published jar includes +the required Ontologymodel classes, Cargo-XML JAXB classes as well as +`jakarta.xml.bind-api` and `jaxb-impl` classes. + + +**Only for version 0.8 and older**: The converter uses Jakarta XML Binding (JAXB), which was part of the Java Enterprise Edition with Java version 8, deprecated in the following Java versions and finally removed in Java 11. @@ -95,6 +105,6 @@ e.g. for Java EE 8, in use with maven: com.sun.xml.bind jaxb-impl - 2.3.3 + 2.3.5 runtime diff --git a/build.gradle b/build.gradle index 0d308f3..38e8863 100644 --- a/build.gradle +++ b/build.gradle @@ -1,24 +1,76 @@ plugins { - id 'java' + id 'java-library' + id 'maven-publish' + id "com.github.johnrengelman.shadow" version "7.1.0" } -sourceCompatibility = JavaVersion.VERSION_1_8 -targetCompatibility = JavaVersion.VERSION_1_8 +/* + * Gets the version name from the latest Git tag, omit leading "v" - yeah! + * Note: a plugin way to do this would be via https://plugins.gradle.org/plugin/net.nemerosa.versioning + */ +def getVersionName = { -> + def stdout = new ByteArrayOutputStream() + exec { + commandLine 'git', 'describe', '--tags', '--always' + standardOutput = stdout + } + def tag = stdout.toString().trim() + return tag.startsWith("v") ? tag.substring(1) : tag +} + +/* + * Gets the commit hash from the latest Git + * Note: a plugin way to do this would be via https://plugins.gradle.org/plugin/net.nemerosa.versioning + */ +def getGitCommitHash = { + def stdout = new ByteArrayOutputStream() + exec { + commandLine 'git', 'log', '-1', '--format="%H"' + standardOutput = stdout + } + return stdout.toString().trim().replace("\"", "") +} + +version = version != null && version != "unspecified" ? version : getVersionName() + +ext { + specVendor = 'International Air Transport Association (IATA)' + product = 'ONE Record Converter' + specTitle = 'ONE Record Ontology-Model' + implVendor = 'Riege Software' + implTitle = product + ' Java Library' + implDescription = implVendor + ' ' + product + ' Java Library' + specVersion = '1.1' + implVersion = version + javaTarget = JavaVersion.VERSION_1_8 +} group 'com.riege' +sourceCompatibility = javaTarget +targetCompatibility = javaTarget -repositories { - flatDir dirs: "$rootProject.projectDir/lib" - mavenCentral() -// maven { -// name = "Riege GitHubPackages" -// url = "https://maven.pkg.github.com/riege/packages" -// credentials { -// username = project.findProperty("github.packages.access.user") ?: System.getenv("GITHUB_PACKAGES_ACCESS_USER") -// password = project.findProperty("github.packages.access.token") ?: System.getenv("GITHUB_PACKAGES_ACCESS_TOKEN") -// } -// } - maven { url 'https://jitpack.io' } +java { + withSourcesJar() // to get a "sourcesJar" task + withJavadocJar() // to get a "javadocJar" task +} + +tasks.withType(Jar) { + manifest { + attributes( + "Built-By" : System.properties['user.name'], + "Build-Revision" : getGitCommitHash(), + "Build-Timestamp" : new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date()), + "Build-Jdk" : "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})", + "Build-OS" : "${System.properties['os.name']} ${System.properties['os.arch']} ${System.properties['os.version']}", + "Created-By" : "Gradle ${gradle.gradleVersion}", + "Specification-Title" : specTitle, + "Specification-Vendor" : specVendor, + "Specification-Version" : specVersion, + "Implementation-Title" : implTitle, + "Implementation-Vendor" : implVendor, + "Implementation-Version" : implVersion + ) + } } dependencies { @@ -26,7 +78,11 @@ dependencies { // but not published on mavenCentral. // Nevertheless it can be retrieved via https://jitpack.io // See also https://jitpack.io/#riege/one-record-ontologymodel - implementation('com.riege:one-record-ontologymodel:1.1.2') { transitive = false } + // jitpack depencecy: + // implementation('com.github.riege:one-record-ontologymodel:1.1.2') { transitive = false } + // github/riege internal dependency: + // implementation('com.riege:one-record-ontologymodel:1.1.2') { transitive = false } + implementation('com.github.riege:one-record-ontologymodel:1.1.2') { transitive = false } // cargoxml-jaxb from riege.com cannot be retrieved via https://jitpack.io // because building it requires access to the Cargo-XML Toolkit schema files // which are not included on GitHub and JitPack has not access to them! @@ -45,3 +101,60 @@ dependencies { test { useJUnitPlatform() } + +shadowJar { + // When working with a Gradle project with the name myApp and version 1.0, + // the default shadowJar task will output a file at: + // build/libs/myApp-1.0-all.jar + // + // to remove the '-all', we set classifier to null: + classifier = null +} +build.dependsOn(shadowJar) + +repositories { + flatDir dirs: "$rootProject.projectDir/lib" + mavenCentral() + mavenLocal() + maven { + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/riege/packages") + credentials { + username = (project.findProperty("github.packages.access.user") ?: System.getenv("GITHUB_PACKAGES_ACCESS_USER")).toString() + password = (project.findProperty("github.packages.access.token") ?: System.getenv("GITHUB_PACKAGES_ACCESS_TOKEN")).toString() + } + } + maven { url 'https://jitpack.io' } +} + +publishing { + publications { + shadow(MavenPublication) { + publication -> project.shadow.component(publication) + groupId group + pom { + name = implTitle + description = implDescription + url = System.getenv("PROJECT_URL") + } + versionMapping { + usage('java-api') { + fromResolutionOf('runtimeClasspath') + } + usage('java-runtime') { + fromResolutionResult() + } + } + } + } + repositories { + maven { + //name = "thisLibrary" + url = System.getenv("MAVEN_PUBLISH_URL") + credentials { + username = System.getenv("MAVEN_PUBLISH_USERNAME") + password = System.getenv("MAVEN_PUBLISH_PASSWORD") + } + } + } +}