Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
51 changes: 51 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: CI

on:
push:
branches: [ master ]
pull_request:

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# JVM the built plugin is tested on (Gradle itself needs JDK 17+)
test-java: [ 11, 17, 21 ]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
# The last one (21) becomes default JAVA_HOME and runs Gradle, the other is found by toolchains
java-version: |
${{ matrix.test-java }}
21
- uses: gradle/actions/setup-gradle@v4
- name: Build and test on Java ${{ matrix.test-java }}
run: ./gradlew check --rerun-tasks -PtestJavaVersion=${{ matrix.test-java }}
- name: Upload test report
if: failure()
uses: actions/upload-artifact@v4
with:
name: test-report-java-${{ matrix.test-java }}
path: build/reports/tests/

example:
# Example project depends on the plugin built from this very commit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: |
11
21
- uses: gradle/actions/setup-gradle@v4
- name: Publish plugin into local Maven repository
run: ./gradlew publishToMavenLocal
- name: Build and test example project
working-directory: example-project-gradle
run: ./gradlew check --rerun-tasks -PuseMavenLocal
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Autobuild Status](https://travis-ci.org/Hubbitus/xjc-documentation-annotation-plugin.svg?branch=master)](https://travis-ci.org/Hubbitus/xjc-documentation-annotation-plugin)
[![CI](https://github.com/Hubbitus/xjc-documentation-annotation-plugin/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/Hubbitus/xjc-documentation-annotation-plugin/actions/workflows/ci.yml)

XJC plugin to bring XSD descriptions into annotations of generated classes
==========================================================================
Expand Down
142 changes: 83 additions & 59 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,104 +1,128 @@
plugins {
id 'java'
id 'java-library'
id 'groovy' // Testing
// http://central.sonatype.org/pages/gradle.html
id 'maven'
id 'maven-publish'
id 'idea'
id 'signing'
}

group 'info.hubbitus'
version '1.1'
group = 'info.hubbitus'
version = '1.2-SNAPSHOT' // 1.1 is released and has the NPE bug (#2), the fix is in the next version

sourceCompatibility = 1.8
// Gradle itself requires JDK 17+, but the built plugin must work on Java 11+
java {
// Also used for Groovy (tests) bytecode level, which otherwise defaults to the JVM running Gradle
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
options.release = 11
}

tasks.withType(Test).configureEach {
useJUnitPlatform() // Spock 2
}

// Run tests on a specific JVM (to check that built plugin works on it): ./gradlew test -PtestJavaVersion=11
if (project.hasProperty('testJavaVersion')) {
tasks.withType(Test).configureEach {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(project.property('testJavaVersion') as int)
}
}
}

tasks.withType(Javadoc).configureEach {
options.encoding = 'UTF-8'
}

repositories {
mavenCentral()
}

dependencies {
compile 'com.sun.xml.bind:jaxb-core:2.3.0.1'
compile "javax.xml.bind:jaxb-api:${versionJaxbIpi}"
testCompile "javax.xml.bind:jaxb-api:${versionJaxbIpi}"
compile "com.sun.xml.bind:jaxb-xjc:${versionJaxb}"
compile "com.sun.xml.bind:jaxb-impl:${versionJaxb}"
api 'com.sun.xml.bind:jaxb-core:2.3.0.1'
api "javax.xml.bind:jaxb-api:${versionJaxbIpi}"
testImplementation "javax.xml.bind:jaxb-api:${versionJaxbIpi}"
implementation "com.sun.xml.bind:jaxb-xjc:${versionJaxb}"
implementation "com.sun.xml.bind:jaxb-impl:${versionJaxb}"

// Logging
compile "org.slf4j:slf4j-api:${versionSlf4j}"
compile "ch.qos.logback:logback-classic:${versionLogback}"
implementation "org.slf4j:slf4j-api:${versionSlf4j}"
implementation "ch.qos.logback:logback-classic:${versionLogback}"

testCompile "org.codehaus.groovy:groovy:${versionGroovy}"
testCompile "org.spockframework:spock-core:${versionSpock}"
testImplementation "org.apache.groovy:groovy:${versionGroovy}"
testImplementation "org.spockframework:spock-core:${versionSpock}"
testRuntimeOnly "org.junit.platform:junit-platform-launcher" // Required by Gradle 9 for JUnit Platform (version is managed by Spock BOM)
}

///////////////////////////////////////////////////////////////
// Artifacts publishing into central OSS repository
// http://central.sonatype.org/pages/gradle.html
task javadocJar(type: Jar) {
archiveClassifier.set('javadoc') // https://discuss.gradle.org/t/publishing-jars-with-classifiers-after-v5-0/30144/2
from javadoc
}

task sourcesJar(type: Jar) {
archiveClassifier.set('sources')
from sourceSets.main.allSource
}

artifacts {
archives javadocJar, sourcesJar
}
signing {
required { gradle.taskGraph.hasTask("uploadArchives") } // https://groups.google.com/forum/#!topic/gaelyk/WfdEDBOzIOM
sign configurations.archives
}
def ossrhUserName = project.findProperty('ossrhUsername') ?: '' // To do not fail on CI when them does not defined
def ossrhPassword = project.findProperty('ossrhPassword') ?: ''

ext{// To do not fail on CI when them does not defined
ossrhUser = (project.hasProperty('ossrhUsername') ? project.property('ossrhUsername') : '')
ossrhPass = (project.hasProperty('ossrhPassword') ? project.property('ossrhPassword') : '')
java {
withJavadocJar()
withSourcesJar()
}

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

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

snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUser, password: ossrhPass)
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java

pom.project {
name project.name
packaging 'jar'
description 'XJC plugin to bring XSD descriptions into annotations of generated classes'
url 'https://github.com/Hubbitus/xjc-documentation-annotation-plugin'
pom {
name = project.name
packaging = 'jar'
description = 'XJC plugin to bring XSD descriptions into annotations of generated classes'
url = 'https://github.com/Hubbitus/xjc-documentation-annotation-plugin'

scm {
connection 'scm:git:https://github.com/Hubbitus/xjc-documentation-annotation-plugin.git'
developerConnection 'scm:git:git@github.com:Hubbitus/xjc-documentation-annotation-plugin.git'
url 'https://github.com/Hubbitus/xjc-documentation-annotation-plugin'
connection = 'scm:git:https://github.com/Hubbitus/xjc-documentation-annotation-plugin.git'
developerConnection = 'scm:git:git@github.com:Hubbitus/xjc-documentation-annotation-plugin.git'
url = 'https://github.com/Hubbitus/xjc-documentation-annotation-plugin'
}

licenses {
license {
name 'MIT'
url 'https://opensource.org/licenses/MIT'
name = 'MIT'
url = 'https://opensource.org/licenses/MIT'
}
}

developers {
developer {
id 'Hubbitus'
name 'Pavel Alexeev'
email 'Pahan@Hubbitus.info'
id = 'Hubbitus'
name = 'Pavel Alexeev'
email = 'Pahan@Hubbitus.info'
}
}
}
}
}

repositories {
maven {
name = 'ossrh'
def releasesRepoUrl = uri('https://oss.sonatype.org/service/local/staging/deploy/maven2/')
def snapshotsRepoUrl = uri('https://oss.sonatype.org/content/repositories/snapshots/')
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
credentials {
username = ossrhUserName
password = ossrhPassword
}
}
}
}

signing {
required = { gradle.taskGraph.hasTask('publish') } // Do not require signing on CI/local builds
sign publishing.publications.mavenJava
}

// /Artifacts publishing into central OSS repository
////////////////////////////////////////////////////
10 changes: 8 additions & 2 deletions example-project-gradle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ This is gradle demo project to show how to use Java code generation from XSD sch

For run generation just invoke:

./gradlew xjcGenerate
./gradlew xjc

After compilation you will find generated classes in [src/main/generated-java](src/main/generated-java)
After compilation you will find generated classes in `build/generated/sources/xjc/java`

Then you may with run tests:

./gradlew check

While the plugin version from [build.gradle](build.gradle) is not released yet, publish it into the local Maven repository
from the parent project and use it with `-PuseMavenLocal`:

(cd .. && ./gradlew publishToMavenLocal)
./gradlew check -PuseMavenLocal
58 changes: 28 additions & 30 deletions example-project-gradle/build.gradle
Original file line number Diff line number Diff line change
@@ -1,58 +1,56 @@
plugins {
id 'java'
id 'org.unbroken-dome.xjc' version '1.4.1' // https://github.com/unbroken-dome/gradle-xjc-plugin
id 'com.github.bjornvester.xjc' version '1.9.1' // https://github.com/bjornvester/xjc-gradle-plugin
id 'idea'
id 'groovy' // For Spock tests
}

group 'info.hubbitus'
version '1.0-SNAPSHOT'
group = 'info.hubbitus'
version = '1.0-SNAPSHOT'

sourceCompatibility = 1.8
java {
toolchain { languageVersion = JavaLanguageVersion.of(11) }
}

repositories {
mavenCentral()
if (project.hasProperty('useMavenLocal')) {
// To try the not yet released plugin, published by `./gradlew publishToMavenLocal` in the parent project
mavenLocal()
}
}

ext{
pluginVersion = '1.1'
pluginVersion = '1.2-SNAPSHOT' // Includes the fix of #2. Set to the released version (e.g. '1.2') once it is available on Maven Central
}

dependencies {
xjcClasspath "info.hubbitus:xjc-documentation-annotation-plugin:$pluginVersion"
xjcPlugins "info.hubbitus:xjc-documentation-annotation-plugin:$pluginVersion"

// Compile dependency for annotations used
compile "info.hubbitus:xjc-documentation-annotation-plugin:$pluginVersion"
testCompile "info.hubbitus:xjc-documentation-annotation-plugin:$pluginVersion"
implementation "info.hubbitus:xjc-documentation-annotation-plugin:$pluginVersion"
testImplementation "info.hubbitus:xjc-documentation-annotation-plugin:$pluginVersion"

// Tests
testCompile 'org.codehaus.groovy:groovy:2.5.5'
testCompile 'org.spockframework:spock-core:1.2-groovy-2.5'
testImplementation 'org.apache.groovy:groovy:5.1.3'
testImplementation 'org.spockframework:spock-core:2.4-groovy-5.0'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher' // Required by Gradle 9 (version is managed by Spock BOM)
}

tasks.withType(Test).configureEach {
useJUnitPlatform() // Spock 2
}

// Results will be in directory `src/main/generated-java`
xjcGenerate {
// Results will be in directory `build/generated/sources/xjc/java`
xjc {
/**
* There:
* 1. Example.xsd is minimal example of functional.
* 2. maven-4.0.0.xsd - example by SOq https://stackoverflow.com/questions/42223784/how-can-i-generate-a-class-from-which-i-can-retrieve-the-xml-of-a-node-as-a-stri
*/
source = fileTree('src/main/resources') { include '*.xsd' }
bindingFiles = fileTree('src/main/jaxb') { include '*.xjb' }
outputDirectory = file('src/main/generated-java')
packageLevelAnnotations = false
targetPackage = 'info.hubbitus.xjc.plugin.example'
extraArgs = [ '-XPluginDescriptionAnnotation' ]
xsdDir = layout.projectDirectory.dir('src/main/resources')
bindingFiles = fileTree('src/main/resources') { include '*.xjb' }
useJakarta = false // The plugin is built on javax (JAXB 2.x) XJC API
defaultPackage = 'info.hubbitus.xjc.plugin.example'
options = [ '-XPluginDescriptionAnnotation' ]
}

// Add generated files into compilation:
// https://stackoverflow.com/questions/36749015/how-do-i-get-intellij-to-recognize-gradle-generated-sources-dir/44740130#44740130
sourceSets.main.java.srcDir new File(buildDir, xjcGenerate.outputDirectory.absolutePath)
idea {
module {
// Marks the already(!) added srcDir as "generated"
generatedSourceDirs += xjcGenerate.outputDirectory
}
}

compileTestGroovy.dependsOn xjcGenerate
Binary file modified example-project-gradle/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#Mon Jan 28 02:58:37 MSK 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.8.0-bin.zip
networkTimeout=10000
retries=0
retryBackOffMs=500
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-all.zip
Loading
Loading