IntelliJ:Rest Assured getting missing input or config - rest-assured

Can anyone help me
Project has been cloned from Bitbucket and locally when i am running the project in the intelliJ the error is displayed
Unable to run the scripts-rest assured in the IntelliJ getting missing input or config. Getting build failure if I change the swagger code-gen dependency also same error is displayed
this is my gradle.build
Buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("io.swagger:swagger-codegen:2.3.1")
}
}
plugins {
id 'java'
id 'io.qameta.allure' version '2.8.1'
}
repositories {
mavenCentral()
}
group 'org.example'
version '1.0-SNAPSHOT'
apply plugin: 'base'
import io.swagger.codegen.DefaultGenerator
import io.swagger.codegen.config.CodegenConfigurator
final def swaggerInput = "swagger.json"
final def swaggerOutputDir = file('build/swagger')
task generateApi {
inputs.file(swaggerInput)
outputs.dir(swaggerOutputDir)
doLast {
final def config = new CodegenConfigurator()
config.setInputSpec(swaggerInput)
config.setOutputDir(swaggerOutputDir.path)
config.setLang('java')
config.setAdditionalProperties([
'dateLibrary' : 'java8'])
config.setImportMappings([
'java.time.OffsetDateTime': 'java.time.Instant',])
config.setTypeMappings([
OffsetDateTime: 'Instant',])
new DefaultGenerator().opts(config.toClientOptInput()).generate()
}
}
clean.doFirst {
delete(swaggerOutputDir)
}
configurations {
swagger
}
sourceSets {
swagger {
compileClasspath = configurations.swaggerCompile
java {
srcDir file("${project.buildDir.path}/swagger/src/main/java")
}
}
main {
compileClasspath += swagger.output
runtimeClasspath += swagger.output
}
test {
compileClasspath += swagger.output
runtimeClasspath += swagger.output
}
}
compileSwaggerJava.dependsOn generateApi
classes.dependsOn swaggerClasses
compileJava.dependsOn compileSwaggerJava
allure {
version = '2.7.0'
downloadLinkFormat = 'https://github.com/allure-framework/allure2/releases/download/2.7.0/allure-2.7.0.zip'
}
dependencies {
// https://mvnrepository.com/artifact/io.rest-assured/rest-assured
compile group: 'io.rest-assured', name: 'rest-assured', version: '4.3.0'
// https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.11.0'
// https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.11.0'
// https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-jsr310
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.11.0'
// https://mvnrepository.com/artifact/org.json/json
compile group: 'org.json', name: 'json', version: '20190722'
compile group: 'org.codehaus.jackson', name: 'jackson-core-asl', version: '1.9.6'
compile group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version: '1.9.6'
compile group: 'com.google.code.gson', name: 'gson', version: '2.1'
compile group: 'io.gsonfire', name: 'gson-fire', version: '1.7.1'
// https://mvnrepository.com/artifact/org.testng/testng
compile group: 'org.testng', name: 'testng', version: '7.0.0'
// https://mvnrepository.com/artifact/org.assertj/assertj-core
compile group: 'org.assertj', name: 'assertj-core', version: '3.16.0'
// https://mvnrepository.com/artifact/io.qameta.allure/allure-rest-assured
compile group: 'io.qameta.allure', name: 'allure-rest-assured', version: '2.13.5'
// https://mvnrepository.com/artifact/io.qameta.allure/allure-testng
compile group: 'io.qameta.allure', name: 'allure-testng', version: '2.13.5'
// https://mvnrepository.com/artifact/org.aeonbits.owner/owner
compile group: 'org.aeonbits.owner', name: 'owner', version: '1.0.10'
// AWS SDK dependencies
compile 'com.amazonaws:aws-java-sdk:1.12.335'
compile 'com.amazonaws:aws-java-sdk-core:1.12.335'
compile 'com.amazonaws:aws-java-sdk-cognitoidp:1.12.335'
compile 'com.amazonaws:aws-java-sdk-ssm:1.12.335'
compile 'software.amazon.awssdk:ssm:2.18.10'
compile 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'
compile 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'
swaggerCompile 'io.swagger:swagger-annotations:1.5.16'
swaggerCompile 'com.squareup.okhttp:okhttp:2.7.5'
swaggerCompile 'com.squareup.okhttp:logging-interceptor:2.7.5'
swaggerCompile 'com.google.code.gson:gson:2.8.1'
swaggerCompile 'io.gsonfire:gson-fire:1.7.1'
compile sourceSets.swagger.output
testCompile 'org.elasticsearch.client:elasticsearch-rest-high-level-client:6.2.4'
testCompile 'org.elasticsearch:elasticsearch:6.2.4'
compile 'com.squareup.okio:okio:1.8.0'
compile 'com.squareup.okhttp:okhttp:2.4.0'
}
test() {
useTestNG() {
if (project.hasProperty('qa4')) {
environment 'env', 'qa4'
}
if (project.hasProperty('qa5')) {
environment 'env', 'qa5'
}
if (project.hasProperty('qa6')) {
environment 'env', 'qa6'
}
if (project.hasProperty('qa7')) {
environment 'env', 'qa7'
}
if (project.hasProperty('qa8')) {
environment 'env', 'qa8'
}
if (project.hasProperty('qa9')) {
environment 'env', 'qa9'
}
if (project.hasProperty('party_controller')) {
suites 'src/test/resources/suites/party_controller.xml'
}
if (project.hasProperty('account_controller')) {
suites 'src/test/resources/suites/account_controller.xml'
}
if (project.hasProperty('payment_source_controller')) {
suites 'src/test/resources/suites/payment_source_controller.xml'
}
if (project.hasProperty('transaction_controller')) {
suites 'src/test/resources/suites/transaction_controller.xml'
}
if (project.hasProperty('maxmind_controller')) {
suites 'src/test/resources/suites/maxmind_testing.xml'
}
if (project.hasProperty('parallel_execution')) {
suites 'src/test/resources/suites/parallel_execution.xml'
}
if (project.hasProperty('regression')) {
suites 'src/test/resources/suites/party_controller.xml'
suites 'src/test/resources/suites/account_controller.xml'
suites 'src/test/resources/suites/payment_source_controller.xml'
suites 'src/test/resources/suites/transaction_controller.xml'
suites 'src/test/resources/suites/maxmind_testing.xml'
suites 'src/test/resources/suites/parallel_execution.xml'
}
}
afterSuite { final suite, final result ->
result.exception?.printStackTrace()
}
}

Related

gradle.properties not taking values from command line

I have gradle.properties file for which I am passing value from command line as below command but not taking the value.
gradle test -DsystemProp.RunnerApplication=QAEnv -Dgroups=CSP-Smoke
My build.gradle file code as follows-
import java.util.concurrent.TimeUnit
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "io.spring.gradle:dependency-management-plugin:1.0.3.RELEASE"
classpath group: 'org.testng', name: 'testng', version: '6.8.+'
}
}
plugins {
id 'java'
}
apply plugin: 'java'
group 'org.csp.xxxx'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
test {
systemProperty "RunnerApplication",System.getProperty("RunnerApplication")
reports {
junitXml.enabled = true
html.enabled = true
reports.junitXml.destination = file("test-output/reports/")
}
def Coregroups = System.getProperty('groups','Core-Smoke \n CSP-Smoke')
useTestNG()
{
includeGroups Coregroups
useDefaultListeners = true
options.suites("src/test/java/TestAPISuite.xml")
//options.listeners << 'com.ddddd.smsApi.qa.framework.listener.CustomListener'
//options.listeners << 'com.dddd.smsApi.qa.framework.listener.EmailListener'
options.listeners << 'org.uncommons.reportng.HTMLReporter'
options.listeners << 'org.uncommons.reportng.JUnitXMLReporter'
systemProperty 'org.uncommons.reportng.title', 'csp_api_automation_results'
}
testLogging.events "passed", "skipped", "failed"
testLogging.exceptionFormat = "full"
//Interceptors
beforeTest { desc ->
println "\n*** Starting execution of test ${desc.className}.${desc.name} ***"
}
afterTest { descriptor, result ->
println "<<< Test ${descriptor.name} resulted in ${result.resultType} and took "+getElaspedTime(result.endTime - result.startTime)+" >>>\n"
}
//Modify the test logging
testLogging {
showStandardStreams = true
exceptionFormat "full"
}
}
sourceSets {
main {
runtimeClasspath = files(output.resourcesDir) + runtimeClasspath
}
test {
runtimeClasspath = files(output.resourcesDir) + runtimeClasspath
}
}
dependencies {
compile group: 'io.rest-assured', name: 'rest-assured', version: '3.0.2'
testCompile group: 'org.testng', name: 'testng', version: '6.8.+'
//An assertion library that is better than JUnit defaults
testCompile 'org.easytesting:fest-assert-core:2.0M10'
//Better reporting for testng. It outputs a nice html report
testCompile 'org.uncommons:reportng:1.1.4'
compile group: 'org.apache.poi', name: 'poi-ooxml', version: '3.15'
compile group: 'net.sourceforge.jexcelapi', name: 'jxl', version: '2.6.12'
compile group: 'commons-lang', name: 'commons-lang', version: '2.6'
compile group: 'com.googlecode.htmlcompressor', name: 'htmlcompressor', version: '1.5.2'
compile group: 'commons-dbutils', name: 'commons-dbutils', version: '1.6'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.6'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.6'
compile group: 'mysql', name: 'mysql-connector-java', version: '6.0.5'
compile group: "com.github.fge", name: "json-schema-validator", version: "2.2.6"
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
compile group: 'org.json', name: 'json', version: '20160810'
compile group: 'org.uncommons', name: 'reportng', version: '1.1.4'
compile group: 'com.google.code.guice-repository', name: 'guice-repository', version: '2.1.0'
compile group: 'org.easytesting', name: 'fest-assert-core', version: '2.0M10'
compile group: 'org.uncommons', name: 'reportng', version: '1.1.4'
compile group: 'org.apache.commons', name: 'commons-csv', version: '1.5'
compile group: 'org.apache.commons', name: 'commons-exec', version: '1.3'
compile group: 'com.opencsv', name: 'opencsv', version: '4.1'
compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.0'
compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.6.1'
compile group: 'com.sun.mail', name: 'javax.mail', version: '1.6.0'
compile group: 'javax.mail', name: 'javax.mail-api', version: '1.6.2'
compileClasspath group: 'org.testng', name: 'testng', version: '6.8.+'
// https://mvnrepository.com/artifact/com.cedarsoftware/json-io
compile group: 'com.cedarsoftware', name: 'json-io', version: '2.6.0'
// https://mvnrepository.com/artifact/org.apache.poi/poi
compile group: 'org.apache.poi', name: 'poi', version: '3.17'
// https://mvnrepository.com/artifact/com.aventstack/extentreports
compile group: 'com.aventstack', name: 'extentreports', version: '4.0.9'
}
def getElaspedTime(def time) {
if(time / 1000 < 1)
{
return String.format("0 min, %.3f sec", time/1000)
}
else
{
return String.format("%d min, %d sec",
TimeUnit.MILLISECONDS.toMinutes(time),
TimeUnit.MILLISECONDS.toSeconds(time) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time))
)
}
}
systemProp.RunnerApplication=dev is the key and value saved in my gradle.properties.
Here I want to run as RunnerApplication=QAEnv so automation can run in different environments
But its is always running on dev even Passing QAEnv in command line.
I would really appreciate your help.
You are passing in two system properties. One is prefixed with systemProp. and the other isn't. This should indicate to you that one of them is wrong. And it's the former :)
There is a use for the systemProp. prefix, but only when declaring system properties through the gradle.properties file. Here, you are declaring them from the command line.
So instead of:
gradle test -DsystemProp.RunnerApplication=QAEnv -Dgroups=CSP-Smoke
Run:
gradle test -DRunnerApplication=QAEnv -Dgroups=CSP-Smoke

Can't load resources in a gradle project

I am using gradle 4.10.2 & IntelliJ IDEA Community Edition 2018.2
Note that this is a jenkins shared library project, hence, deviates from the standard gradle project structure.
The project shown in the image is an existing Gradle project. I am simply trying to load a properties file viz. mailTemplate.properties in a Groovy class EmailTemplate but the problem is that irrespective of where I keep it(like shown in the image), it's not loaded. I created a separate test gradle project and placed it in the default (src/main/resources) dir. and it works like a breeze.
I tried creating 'resources' at two places but in vain.
The build.gradle is:
buildscript {
repositories {
ivy {
url "$repositoryURL/$resolveRepository"
}
maven {
url "$repositoryURL/$resolveRepository"
}
}
dependencies {
classpath "tools.gradle.plugin:ReleasePlugin:1.10.0"
classpath "tools.gradle.plugin:qualityreport:v1.14.4"
}
}
group 'tools'
apply plugin: 'groovy'
apply plugin: 'tools.gradle.plugin.releaseplugin'
apply plugin: 'tools.gradle.plugin.qualityreport'
sourceSets {
main {
groovy {
srcDirs = ['src']
}
}
test {
groovy {
srcDirs = ['test/groovy']
}
}
}
repositories {
addAll(buildscript.repositories)
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.4.15'
compile 'org.codehaus.groovy:groovy-json:2.4.9'
compile 'com.cloudbees:groovy-cps:1.1'
compile 'org.slf4j:slf4j-api:1.7.21'
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-core:1.3'
testCompile 'net.bytebuddy:byte-buddy:1.6.4'
testCompile ('org.spockframework:spock-core:1.1-groovy-2.4') {
exclude group: 'org.codehaus.groovy'
}
testCompile gradleTestKit()
testCompile group: 'com.lesfurets', name: 'jenkins-pipeline-unit', version: '1.1'
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.23.4'
testCompile group: 'tools.gradle.plugin', name: 'jenkins-shared-stages', version: 'v2.48.0'
// jenkins dependencies
testCompile 'org.jenkins-ci.plugins:script-security:1.34#jar'
}
task copySharedLibs(type: Copy, group: "PipelineTest") {
from '.'
into 'build/libs/jenkins-shared-pipelines#master'
include 'src/**'
include 'vars/**'
}
test.dependsOn(copySharedLibs)
Gradle groovy plugin expects resources to be at src/main/resources by default. In case the resources are located some other folder then it should be configured in the sourceSets. You can try the below assuming your resource file are also withing your src folder.
sourceSets {
main {
groovy {
srcDirs = ['src']
}
resources {
srcDirs = ['src']
}
}
test {
groovy {
srcDirs = ['test/groovy']
}
resources {
srcDirs = ['test/groovy']
}
}
}

Adding jcenter() in rootlevel repositories breaks my build

I have a project with a Gradle buildscript and I added the bmuschko/gradle-docker-plugin to create and push image on new builds.
However I cant use the plugin if I don't specify jcenter() in root level repositories, but that breaks my build, so im kinda lost.
If I add the root level jcenter() it fails the build with:
Could not resolve all dependencies for configuration ':compileClasspath'.
Could not find com.sleepycat:je:7.0.6. Searched in the following locations:
https://jcenter.bintray.com/com/sleepycat/je/7.0.6/je-7.0.6.pom
https://jcenter.bintray.com/com/sleepycat/je/7.0.6/je-7.0.6.jar
https://repo1.maven.org/maven2/com/sleepycat/je/7.0.6/je-7.0.6.pom
https://repo1.maven.org/maven2/com/sleepycat/je/7.0.6/je-7.0.6.jar
https://nexus.company.com/content/groups/public/com/sleepycat/je/7.0.6/je-7.0.6.pom
https://nexus.company.com/content/groups/public/com/sleepycat/je/7.0.6/je-7.0.6.jar
Required by: project : > org.jpos:jpos:2.1.1
However if I don't add it i get this:
Could not resolve all dependencies for configuration ':dockerJava'.
Could not find com.aries:docker-java-shaded:3.1.0-rc-3. Searched in the following locations:
https://nexus.company.com/content/groups/public/com/aries/docker-java-shaded/3.1.0-rc-3/docker-java-shaded-3.1.0-rc-3.pom
https://nexus.company.com/content/groups/public/com/aries/docker-java-shaded/3.1.0-rc-3/docker-java-shaded-3.1.0-rc-3-cglib.jar
Required by: project :
Should I perhaps build Java shaded and include in our local Maven repo?
Here is the script:
buildscript {
repositories {
jcenter()
mavenCentral()
maven {
url = 'https://nexus.company.com/content/repositories/snapshots/'
credentials {
username 'na'
password 'na'
}
}
}
dependencies {
classpath group: 'com.company.gradle', name: 'cpmgradle', version: '0.1-SNAPSHOT'
classpath 'com.bmuschko:gradle-docker-plugin:3.4.4'
}
}
// ADDING THIS BREAKS MY BUILD BUT IS NECESSARY FOR DOCKER PLUGIN TO WORK
repositories {
jcenter()
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'com.company.gradle.java'
apply plugin: 'com.bmuschko.docker-remote-api'
projectinfo {
group = 'com.company.mesb'
artifact = 'MESB'
version = '1.29.DEV-SNAPSHOT'
description = 'MESB'
packaging = 'jar'
}
dependencies {
compile 'org.jpos:jpos:2.1.1'
compile 'org.jdom:jdom2:2.0.6'
compile 'org.json:json:20140107'
compile 'com.company.javasdk:JavaSDK:1.1.JDOM2-SNAPSHOT'
compile 'com.company.javasdk:Base64:1.0'
compile 'org.apache.wss4j:wss4j-ws-security-dom:2.0.3'
compile 'org.apache.santuario:xmlsec:2.0.3'
compile 'org.slf4j:slf4j-log4j12:1.7.10'
compile 'com.google.code.gson:gson:2.3.1'
compile 'org.bouncycastle:bcprov-jdk15on:1.54'
compile 'org.bouncycastle:bcpkix-jdk15on:1.54'
compile 'junit:junit:4.12'
compile 'org.jsoup:jsoup:1.9.2'
compile 'org.apache.commons:commons-lang3:3.4'
compile 'com.ibm:mq:5.3.07'
compile 'com.ibm:mq.pcf:5.3.07'
compile 'com.ibm:mq.jmqi:5.3.07'
compile 'com.ibm:mq.headers:5.3.07'
compile 'com.ibm:mq.commonservices:5.3.07'
compile 'com.ibm:connector:1.0.0'
runtime 'jaxen:jaxen:1.1.6'
runtime 'xalan:xalan:2.7.2'
runtime 'org.postgresql:postgresql:8.0-311.jdbc3'
runtime 'commons-logging:commons-logging:1.2'
}
compileJava {
sourceCompatibility = 1.6
targetCompatibility = 1.6
options.fork = true
options.compilerArgs << '-XDignore.symbol.file'
options.forkOptions.executable = 'javac'
}
task libs(type: Copy) {
description = "Copies dependencies to the 'lib' directory of the deployment."
def libsDir = new File("$buildDir", 'libs')
libsDir.mkdirs()
def dockerDir = new File("$buildDir", 'docker')
dockerDir.mkdirs()
from project.configurations.runtime
into libsDir
}
task bundleZip(type: Zip) {
from projectDir
include 'xsl/**'
include 'conf/**'
include 'js/**'
include 'test/**'
include 'mesb.sh'
from(tasks.libs.outputs) {
include 'MESB*'
}
into project.projectinfo.version
}
tasks.bundleZip.dependsOn jar
tasks.bundleZip.dependsOn libs
def dockerUsername = project.properties['dockerUsername'] ?: ""
def dockerPassword = project.properties['dockerPassword'] ?: ""
docker {
registryCredentials {
username = dockerUsername
password = dockerPassword
}
}
task buildImage(type: com.bmuschko.gradle.docker.tasks.image.DockerBuildImage) {
doFirst {
copy {
from "${buildDir}/libs/MESB-${projectinfo.version}.jar"
into "${buildDir}/docker"
rename { String fileName ->
fileName.replace("-${projectinfo.version}", "")
}
}
copy {
from "docker/jdk/Dockerfile"
into "${buildDir}/docker"
}
copy {
from "xsl"
into "${buildDir}/docker/xsl"
}
copy {
from "conf"
into "${buildDir}/docker/conf"
}
copy {
from "test"
into "${buildDir}/docker/test"
}
copy {
from "${buildDir}/libs"
into "${buildDir}/docker/libs"
}
}
inputDir = project.file("${buildDir}/docker")
tag = "company/mesb:${projectinfo.version}"
}
tasks.buildImage.dependsOn build
task pushImage(type: com.bmuschko.gradle.docker.tasks.image.DockerPushImage) {
imageName = "company/mesb"
tag = "${projectinfo.version}"
}
tasks.pushImage.dependsOn buildImage
artifacts {
archives bundleZip
}
/* Remove the default JAR file from the uploaded artifacts */
configurations.archives.artifacts.with { archives ->
def jarArtifact
archives.each {
if (it.file =~ 'jar') {
jarArtifact = it
}
}
remove(jarArtifact)
}
jar {
dependsOn configurations.runtime
manifest {
attributes 'Main-Class': 'main.MESB'
}
}
tasks.build.dependsOn libs
sourceSets {
main {
java {
srcDir 'src'
}
}
}
Apparently moving root repository definitions benieth the apply plugins section solved this.
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'com.company.gradle.java'
apply plugin: 'com.bmuschko.docker-remote-api'
repositories {
jcenter()
mavenCentral()
}
Don't know whether you have solved your issue but either way...
I encountered a similar issue regarding:
Could not resolve all dependencies for configuration ':dockerJava'.
Could not find com.aries:docker-java-shaded:3.1.0-rc-3.
We solved it by adding the following
repositories {
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}

Building uberjar with gradle fails in jenkins

Hi I'm using gradle to create a fat jar.
It works properly on my local machine but fails when running from Jenkins.
My local gradle version is: GradleVersion.current().getVersion()=2.2.1
The one in Jenkins: GradleVersion.current().getVersion()=2.4
build.gradle looks like
Is there anything about gradle version?
I just run tasks: clean uberjar
apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'maven'
sourceCompatibility = 1.5
version = '1.0'
repositories {
mavenLocal()
mavenCentral()
}
def classifier = 'producao'
println "GradleVersion.current().getVersion()="+ GradleVersion.current().getVersion()
println "Project env = '${project.hasProperty('env')}'"
// para passar parametros -Penv=homologacao
if (project.hasProperty('env') && project.getProperty('env') == 'homologacao') {
classifier = 'homologacao'
}
println "Classifier = ${classifier}"
println "Using 'com.mundi:OneStop:1.0:${classifier}'"
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.3.10'
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
compile 'net.sf.opencsv:opencsv:2.3'
compile "com.mundi:OneStop:1.0:${classifier}"
compile 'org.apache.commons:commons-lang3:3.4'
testCompile group: 'junit', name: 'junit', version: '4.+'
testCompile "org.spockframework:spock-core:1.0-groovy-2.3"
}
task listJars << {
configurations.compile.each { File file -> println file.name }
}
test { systemProperties 'property': 'value' }
uploadArchives {
repositories { flatDir { dirs 'repos'
} }
}
task copyToLib(type: Copy) {
into "build/classes/main"
sourceSets {
main { resources { srcDir 'src/main/resources' } }
}
from sourceSets.main.resources
}
task uberjar(type: Jar, group:'Extra Jars', description: 'Assembles a single uber jar archive containing the main classes along with all its dependencies.',
dependsOn:[':copyToLib',
':compileJava',
':compileGroovy',
':processResources'
]) {
classifier = 'uber'
destinationDir new File("$buildDir")
from files(sourceSets.main.output.classesDir)
from(configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) }) {
//exclude all META-INF that may appear in any dependant jar
exclude "META-INF/**"
}
version = '1.0'
baseName = "OneStopMonitor"
manifest {
attributes 'Main-Class': "com.onestop.monitor.AirMonitor",
'Implementation-Title': 'OneStop Monitor',
'Implementation-Version': version
}
}
group = 'com.onestop'
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file:///Users/eduardorodrigues/.m2/repository")
}
}
}

How to compile multiple xsd files in Gradle JAXB/XJC?

I'm fairly new to Gradle and I am facing some issues trying to compile multiple schema files using Gradle Ant XJC.
Using the below code, I'm able to compile 1 schema successfully. However, I'm not sure how to do the same for multiple schema files.
Any advice please?
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task : XJC ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
final def packageName = "org.test.webservice.domain"
final def schemaFile = "misc/resources/schemas/employee-v3/wadl/employee.xsd"
configurations { provided }
project.ext.generatedSrcDir = file("$buildDir/generated-src")
dependencies {
provided 'com.sun.xml.bind:jaxb-impl:2.2.6'
provided 'com.sun.xml.bind:jaxb-xjc:2.2.6'
}
task jaxb {
println 'Starting JAXB XJC...'
ext {
packagePath = packageName.replaceAll("\\.", "/")
srcFile = file(schemaFile)
destDir = new File(project.ext.generatedSrcDir, packagePath)
}
inputs.file srcFile
outputs.dir destDir
project.ext.generatedSrcDir.mkdirs()
ant.taskdef(name: 'xjc',
classname: 'com.sun.tools.xjc.XJCTask',
classpath: configurations.provided.asPath)
doLast {
project.ext.generatedSrcDir.mkdirs()
ant.xjc(schema: srcFile, package: packageName,
destdir: project.ext.generatedSrcDir)
}
task generateSources() {}
sourceSets.main.java.srcDirs += project.ext.generatedSrcDir
generateSources.dependsOn jaxb
compileJava.dependsOn generateSources
eclipseClasspath.dependsOn generateSources
// ideaClasspath.dependsOn generateSources
}
I solved it myself. Here is the working solution.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task : XJC ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
final def packageName = "org.test.webservice.domain"
final def schemaDir = "misc/resources/schemas/employee-sda-v3/wadl"
configurations { provided }
project.ext.generatedSrcDir = file("$buildDir/generated-src")
dependencies {
provided 'com.sun.xml.bind:jaxb-impl:2.2.6'
provided 'com.sun.xml.bind:jaxb-xjc:2.2.6'
}
task jaxb {
println 'Starting JAXB XJC...'
ext {
packagePath = packageName.replaceAll("\\.", "/")
destDir = new File(project.ext.generatedSrcDir, packagePath)
}
outputs.dir destDir
project.ext.generatedSrcDir.mkdirs()
ant.taskdef(name: 'xjc', classname: 'com.sun.tools.xjc.XJCTask', classpath: configurations.provided.asPath)
doLast {
project.ext.generatedSrcDir.mkdirs()
ant.xjc(package: packageName, destdir: project.ext.generatedSrcDir){
schema(dir: ${schemaDir}, includes: "**/*.xsd")
}
}
task generateSources() {}
sourceSets.main.java.srcDirs += project.ext.generatedSrcDir
generateSources.dependsOn jaxb
compileJava.dependsOn generateSources
eclipseClasspath.dependsOn generateSources
// ideaClasspath.dependsOn generateSources
}
jacobono's gradle-jaxb-plugin compiles all schemas in the input directory.
I find this plugin more stable than Ant XJC. In my project, on some machines Ant XJC does not generate classes for no reason, although the results is successful. Maybe this is matter of configuration but IMHO even setup is easier with the plugin.
Here is one more working example. I put complete version of my build.gradle file.
You can setup directory and include filter on schema inside of xjc.
if you have 'nested "$" element is not supported' error like above, then below my example will help
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
sourceCompatibility = 1.8
targetCompatibility = 1.8
task genJaxb {
ext.sourcesDir = "${buildDir}/generated-sources/jaxb"
ext.classesDir = "${buildDir}/classes/jaxb"
ext.schemaDir = "${projectDir}/src/main/resources"
outputs.dir classesDir
doLast() {
project.ant {
taskdef name: "xjc", classname: "com.sun.tools.xjc.XJCTask",
classpath: configurations.jaxb.asPath
mkdir(dir: sourcesDir)
mkdir(dir: classesDir)
xjc(destdir: sourcesDir) {
schema(dir: schemaDir, includes: "**/*.xsd")
arg(value: "-wsdl")
produces(dir: sourcesDir, includes: "**/*.java")
}
javac(destdir: classesDir, source: 1.8, target: 1.8, debug: true,
debugLevel: "lines,vars,source",
classpath: configurations.jaxb.asPath,
includeantruntime: "false") {
src(path: sourcesDir)
include(name: "**/*.java")
include(name: "*.java")
}
copy(todir: classesDir) {
fileset(dir: sourcesDir, erroronmissingdir: false) {
exclude(name: "**/*.java")
}
}
}
}
}
jar {
baseName = 'myProject'
version = '0.0.1'
from genJaxb.classesDir
}
repositories {
mavenLocal()
mavenCentral()
}
configurations {
jaxb
}
dependencies {
compile("com.google.code.gson:gson:2.3",
"commons-lang:commons-lang:2.6",
"commons-collections:commons-collections:3.2.1",
"commons-codec:commons-codec:1.10",
"commons-io:commons-io:2.4",
"org.springframework.ws:spring-ws-core:2.2.1.RELEASE"
)
compile("wsdl4j:wsdl4j:1.6.1")
jaxb("com.sun.xml.bind:jaxb-xjc:2.2.4-1")
compile(files(genJaxb.classesDir).builtBy(genJaxb))
testCompile("junit:junit",
"org.powermock:powermock-api-mockito:1.6.2",
"org.powermock:powermock-module-junit4:1.6.2",
)
}
task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}
This could be the easiest solution without any external plugin.
Does it have any other impact?
task prepareXSD2Java{
def xsdSourceDir = xsdPackageName.replace(".","/")
FileTree xsdFilesTree = fileTree(dir: "$projectResourceDir/$xsdSourceDir")
xsdFilesTree.include '*.xsd'
doLast{
xsdFilesTree.getFiles().each {
File xsdFile ->
def xsdPackageExt = xsdFile.name.replace("-","_")
xsdPackageExt = xsdPackageExt.take(xsdPackageExt.lastIndexOf("."))
String xsdFileName = xsdFile.getAbsolutePath();
exec {
executable = "xjc"
args = [ "-d", "$projectSourceDir", "-p",
"$xsdPackageName.$xsdPackageExt", "$xsdFileName" ]
}
}
}
}

Resources