Skip to content

Commit

Permalink
prepare release 8.1, include required JAXB libraries in published JAR
Browse files Browse the repository at this point in the history
  • Loading branch information
mskopp committed Oct 27, 2021
1 parent c21d6e2 commit 4f87366
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 23 deletions.
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ This project requires an internet connection to download required additional lib
Note that the generated classes contain references to classes from the
```javax.xml.bind.annotation``` package. This package is included in Java 8 but no longer in Java 11.

Therefore, when the generated classes are used with JDK 11, it is recommended to
### Version > 8.0
Versions younger than 8.0 contain the `jakarta.xml.bind-api` bundled within the library jar.
It is no longer required to declare a dependency when using the library.

### Version 8.0
When the generated classes are used with JDK 11, it is recommended to
add a dependency to the ```jakarta.xml.bind-api```, e.g. in gradle with

implementation 'jakarta.xml.bind:jakarta.xml.bind-api:2.3.3'
Expand Down Expand Up @@ -97,25 +102,31 @@ Windows with Cargo-XML 4th Edition installed:
Publishing the generated JAR file from directory ```build/libs``` is required to
provide the generated JAXB classes for 3rd partties.

## Publishing to MavenLocal (for developers)
### Publishing to MavenLocal (for developers)
Project supports pubishing to local, which might be useful to generate a maven
`pom` file containing the dependency to `jakarta.xml.bind-api`dependency
`pom` file containing dependencies as required:

./gradlew -Pschemadir=$HOME/cargoxml-schema clean publishToMavenLocal

### Versioning

Recommendation is to use a version pattern for releases which matches the versioning of the
underlying Cargo-XML Toolkit, e.g.
underlying Cargo-XML Toolkit in the major release number, e.g. using version `8.0` to
release a version which is based upon IATA Cargo-XML Toolkit 8.
Minor and Patch releases should follow the [semantic versioning pattern](https://semver.org/)
with using version tags in git.

version = '8.0'
It is possible to overwrite the latest git version tag by providing the version directly to git, e.g.

./gradlew -Pversion=8.2-SNAPSHOT -Pschemadir=$HOME/cargoxml-schema clean publishToMavenLocal

in build.gradle to release a version which is based upon IATA Cargo-XML Toolkit 8.

### Publish on GitHub
Easiest way of publishing is usage of publishing via [GitHub releases](../../releases)
on GitHub website and uploading the generated JAR file from directory ```build/libs```.

Publishing is a **manual process** because building the jar requires local access to the schema directory.
Recommendation is create the version tag in `git` first, then publish on https://github.com/.


### Publishing on MavenCentral
It's a great idea to make the generated JAR file available on
Expand Down
71 changes: 55 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
plugins {
id 'java-library'
id 'maven-publish'
id("com.github.bjornvester.xjc") version "1.6.0"
id "com.github.bjornvester.xjc" version "1.6.0"
id "com.github.johnrengelman.shadow" version "7.1.0"
}

dependencies {
/*
* The following bindings are not required to BUILD or JAR this project
* but the generated classes in the jar depend upon them.
* (although included in Java 8)
* In order to publish properly, the dependencies are declared.
*/
api 'jakarta.xml.bind:jakarta.xml.bind-api:2.3.3'
/*
* 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
}

jar {
exclude("**/schema/CXML-*/**")
exclude("**/schema/X*-*.00/**")
/*
* 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 {
// for Cargo-XML 8th Edition, the path is
// "%LOCALAPPDATA%\IATA\Reader\1.0.0.0\Library\CXML 8th\Downloads\Schemas"
Expand All @@ -40,6 +55,22 @@ ext {
javaTarget = JavaVersion.VERSION_1_8
}

dependencies {
/*
* The following bindings are not required to BUILD or JAR this project
* but the generated classes in the jar depend upon them.
* (although included in Java 8)
* In order to publish properly, the dependencies are declared.
*/
api 'jakarta.xml.bind:jakarta.xml.bind-api:2.3.3'
api 'com.sun.xml.bind:jaxb-impl:2.3.5'
}

jar {
exclude("**/schema/CXML-*/**")
exclude("**/schema/X*-*.00/**")
}

task unzipschema(type: Copy) {
def thedirectory = new File(schemadir)

Expand Down Expand Up @@ -95,12 +126,19 @@ xjc {
}
}

group = 'org.iata.cargoxml'
version = '8.0'

group = 'com.riege'
sourceCompatibility = javaTarget
targetCompatibility = javaTarget

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
}

tasks.withType(Jar) {
manifest {
attributes(
Expand All @@ -125,8 +163,9 @@ repositories {
publishing {
publications {
thisLibrary(MavenPublication) {
publication -> project.shadow.component(publication)
groupId group
from components.java
// from components.java
pom {
name = implTitle
description = implDescription
Expand Down

0 comments on commit 4f87366

Please sign in to comment.