Skip to content

Commit

Permalink
Change release-policy: include required dependencies in published JAR
Browse files Browse the repository at this point in the history
  • Loading branch information
mskopp committed Oct 27, 2021
1 parent 41148d9 commit ed07004
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 20 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,32 @@ 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):

<dependency>
<groupId>com.github.riege</groupId>
<artifactId>one-record-converter</artifactId>
<version>0.8.0</version>
<version>0.9.0</version>
</dependency>

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.
Expand All @@ -95,6 +105,6 @@ e.g. for Java EE 8, in use with maven:
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.3</version>
<version>2.3.5</version>
<scope>runtime</scope>
</dependency>
145 changes: 129 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,32 +1,88 @@
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 {
// one-record-ontologymodel from riege.com is a public GitHub repository
// 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!
Expand All @@ -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")
}
}
}
}

0 comments on commit ed07004

Please sign in to comment.