Gradle: Unable to initialize POM pom-default.xml: Failed to validate POM - java

I am getting 'Unable to initialize POM pom-default.xml: Failed to validate POM' when uploading archive using 'uploadArchives'. I tried maven-publish plugin also but still no luck. Any help will be appriciated.
Below is my gradle.build file:
buildscript {
ext {
springBootVersion = '1.2.6.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath('io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE')
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'maven'
apply plugin: 'signing'
jar {
baseName = 'zmailapp'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-ws')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.lau ncher.StandardVMType/JavaSE-1.8'
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.7'
}
task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
}
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives javadocJar, sourcesJar
}
signing {
sign configurations.archives
}
group = "com.adadyn"
archivesBaseName = "zmailapp"
version = "0.0.1-SNAPSHOT"
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: "https://oss.sonatype.org/service/local/staging/deploy /maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
pom.project {
name 'ZmailApp'
packaging 'jar'
// optionally artifactId can be defined here
description 'A application used as an example on how to set up pushing its components to the Central Repository.'
url 'http://zmailapp.com'
scm {
connection 'scm:git:https://github.com/zishan2050/ZmailApp'
developerConnection 'scm:git:https://github.com/zishan2050/ZmailApp'
url 'https://github.com/zishan2050/ZmailApp'
}
licenses {
license {
name 'The Apache License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id 'manfred'
name 'Manfred Moser'
email 'manfred#sonatype.com'
}
}
}
}
}
}

I solved the above error by adding below code in pom.project{ } block of gradle.build file.
parent {
groupId "org.springframework.boot"
artifactId "spring-boot-starter-parent"
version "${project.bootVersion}"
}

Related

Eclipse libGDX project can't resolve gradle dependency of local repo but CLI has no problem?

I'm trying a libgdx project depending on a lib published in local repo with maven-publish:
// to publish locally:
// ~/gdx-gltf$ ./gradlew gltf:publishToMavenLocal
apply plugin: 'maven-publish'
publishing {
publications {
mavenJava(MavenPublication) {
groupId = 'io.github.odys-z'
artifactId = 'gdx-gltf'
version = '0.1.0-SNAPSHOT'
from components.java
}
}
}
When I running the depending desktop with gradlew CLI, it's working:
./gradlew desktop:run
But in eclipse and right click the BasicTweenTest class (gradle project.ext.mainClassName) and run as java application, eclipse reported errors:
com.badlogic.gdx.utils.GdxRuntimeException: java.lang.Error: Unresolved compilation problems:
sceneAsset cannot be resolved to a variable
GLTFLoader cannot be resolved to a type
SceneModel cannot be resolved to a type
scenes cannot be resolved or is not a field
animationLoader cannot be resolved to a variable
The missing type is in the local repo dependency, gdx-gltf-0.1.0-SNAPSHOT. No matter what I cleaned projects or refreshed gradle, the error persisting appear.
Eclipse Screenshot with stacktrace report
desktop/build.gradle:
apply plugin: "java"
sourceCompatibility = 1.8
sourceSets.main.java.srcDirs = [ "src/", "test/" ]
sourceSets.main.resources.srcDirs = ["../android/assets", "test"]
// project.ext.mainClassName = "io.oz.wnw.norm.desktop.DesktopLauncher"
// project.ext.mainClassName = "io.oz.wnw.norm.desktop.PlaneStarTest"
project.ext.mainClassName = "io.oz.wnw.norm.desktop.BasicTweenTest"
project.ext.assetsDir = new File("../android/assets")
task run(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = project.assetsDir
ignoreExitValue = true
}
task debug(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = project.assetsDir
ignoreExitValue = true
debug = true
}
task dist(type: Jar) {
manifest {
attributes 'Main-Class': project.mainClassName
}
from {
configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
with jar
}
dist.dependsOn classes
The other two tests commented out above can run both in CLI and eclipse, which don't depend on the local published package. Any idea?
--------- parent project/build.gradle ----------
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
// jcenter()
google()
}
dependencies {
classpath 'org.wisepersist:gwt-gradle-plugin:1.0.9'
classpath 'com.android.tools.build:gradle:7.0.0-alpha08'
}
}
allprojects {
version = '1.0'
ext {
appName = "wn cloud"
gdxVersion = '1.9.14'
gltfVersion = '0.1.0-SNAPSHOT'
roboVMVersion = '2.3.8'
box2DLightsVersion = '1.4'
ashleyVersion = '1.7.0'
aiVersion = '1.8.0'
}
repositories {
mavenLocal()
maven { url "http://maven.aliyun.com/nexus/content/groups/public" }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
mavenCentral()
// jcenter()
google()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
}
project(":desktop") {
apply plugin: "java-library"
dependencies {
implementation project(":core")
api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
}
}
project(":android") {
apply plugin: "android"
configurations { natives }
dependencies {
implementation project(":core")
api "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
}
}
project(":html") {
apply plugin: "java-library"
apply plugin: "gwt"
apply plugin: "war"
dependencies {
implementation project(":core")
api "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion"
api "com.badlogicgames.gdx:gdx:$gdxVersion:sources"
api "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources"
api "com.badlogicgames.ashley:ashley:$ashleyVersion:sources"
}
}
project(":core") {
apply plugin: "java-library"
apply plugin: 'eclipse'
eclipse {
classpath {
downloadSources=true
downloadJavadoc = true
}
}
dependencies {
api "com.badlogicgames.gdx:gdx:$gdxVersion"
api "com.badlogicgames.ashley:ashley:$ashleyVersion"
api 'io.github.odys-z:gdx-gltf:0.1.0-SNAPSHOT'
}
}
I faced the same problem. Turns out that LibGDX works with JDK 7 and any version compiled above won't work.
You need to enforce java to compile at version 1.7 before publishing locally
apply plugin: 'java'
sourceCompatibility = 1.7
targetCompatibility = 1.7

groovy.lang.MissingPropertyException: Could not get unknown property

Caused by: groovy.lang.MissingPropertyException: Could not get unknown
property 'NEXUS_USERNAME' for object of type
org.gradle.api.publication.maven.internal.deployer.DefaultGroovyMavenDeployer.
I do not understand this problem. even though I know his mistake. but I still don't understand how to solve the problem.
this is my Gradle code
apply plugin: 'idea'
apply plugin: 'kotlin'
apply plugin: 'maven'
apply plugin: 'signing'
apply plugin: 'org.jetbrains.dokka'
buildscript {
ext.version_kotlin = '1.3.21'
ext.version_dokka = '0.9.17'
ext.version_java_util = '[2.0.1,2.1.0)'
ext.version_slf4j = '[1.7,1.8)'
ext.version_mockito = '[2.8,2.9)'
ext.version_logback = '[1.2,1.3)'
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$version_kotlin"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$version_dokka"
}
}
dokka {
outputFormat = 'html'
outputDirectory = "$projectDir/doc/javadoc"
}
version VERSION
group GROUP
repositories {
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$version_kotlin"
api "com.github.michael-rapp:java-util:$version_java_util"
implementation "org.slf4j:slf4j-api:$version_slf4j"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$version_kotlin"
testImplementation "org.mockito:mockito-core:$version_mockito"
testImplementation "ch.qos.logback:logback-classic:$version_logback"
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from tasks.javadoc.destinationDir
}
task sourcesJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'sources'
}
artifacts {
archives jar
archives javadocJar
archives sourcesJar
}
signing {
required { gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
pom.groupId = GROUP
pom.artifactId = POM_ARTIFACT_ID
pom.version = VERSION
repository(url: RELEASE_REPOSITORY_URL) {
authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD)
}
snapshotRepository(url: SNAPSHOT_REPOSITORY_URL) {
authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD)
}
pom.project {
name POM_NAME
packaging POM_PACKAGING
description POM_DESCRIPTION
url POM_URL
scm {
url POM_SCM_URL
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
}
licenses {
license {
name POM_LICENCE_NAME
url POM_LICENCE_URL
distribution POM_LICENCE_DIST
}
}
developers {
developer {
id POM_DEVELOPER_ID
name POM_DEVELOPER_NAME
}
}
}
}
}
}
in the section is red " MavenDeployment "
I take raw materials on GitHub. I want to use this application to be able to use APRIORI logic. if anyone can help please comment below. for more details, I also include the address where I downloaded it Link

spring boot - No auto configuration found in META-INF/spring.factories - gradle

I am creating javafx app with spring boot in background. To do this I used this library: springboot-javafx-support Every time when I start it I get exception "No auto configuration found in META-INF/spring.factories". I have no idea what I am doing wrong. I guess it must be something wrong in my gradle build script.
Below you can find gradle.build file
buildscript {
ext {
springBootVersion = '2.0.1.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
//apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'pl.opfol.subiekt'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.9
sourceSets {
main.java.srcDirs += 'build/generated/source/apt/main'
}
jar {
enabled = true
}
bootJar {
mainClassName = 'pl.opfol.subiekt.util.MainApp'
}
repositories {
mavenCentral()
maven {
url "https://artifact.aspose.com/repo"
}
maven {
url "https://dl.bintray.com/jerady/maven"
}
}
dependencies {
compile 'org.projectlombok:lombok:1.16.20'
compile('org.springframework.boot:spring-boot-starter')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-validation')
compile('org.springframework.boot:spring-boot-starter-logging')
compile('com.h2database:h2:1.4.197')
compile('javax.mail:javax.mail-api:1.6.1')
compile('com.sun.mail:javax.mail:1.6.1')
compile('commons-io:commons-io:2.6')
compile('commons-codec:commons-codec:1.11')
compile('org.apache.commons:commons-collections4:4.1')
compile('org.apache.commons:commons-lang3:3.7')
compile('commons-configuration:commons-configuration:1.10')
compile('com.aspose:aspose-words:17.3.0:jdk16')
compile('com.microsoft.sqlserver:mssql-jdbc:6.4.0.jre9')
compile('javax.annotation:javax.annotation-api:1.3.2')
compile('org.controlsfx:controlsfx:9.0.0')
compile('com.itextpdf:itext7-core:7.1.1')
compile('javax.xml.bind:jaxb-api:2.3.0')
compile('com.jfoenix:jfoenix:9.0.0')
compile('de.roskenet:springboot-javafx-support:2.1.6')
compile('de.jensd:fontawesomefx-controls:9.1.2')
compile('de.jensd:fontawesomefx-commons:9.1.2')
compile('de.jensd:fontawesomefx-weathericons:2.0.10-9.1.2')
compile('de.jensd:fontawesomefx-materialicons:2.2.0-9.1.2')
compile('de.jensd:fontawesomefx-materialdesignfont:2.0.26-9.1.2')
compile('de.jensd:fontawesomefx-octicons:4.3.0-9.1.2')
compile('de.jensd:fontawesomefx-fontawesome:4.7.0-9.1.2')
compile('de.jensd:fontawesomefx-materialstackicons:2.1-5-9.1.2')
compile('de.jensd:fontawesomefx-icons525:4.2.0-9.1.2')
compile('de.jensd:fontawesomefx-emojione:3.1.1-9.1.2')
compileOnly ('org.hibernate:hibernate-jpamodelgen:5.2.16.Final')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
I had same problem, make sure you run it on JRE 1.8.

Spring annotation #Autowired cannot be imported in IntelliJ using gradle

As the title says. I'm using IntelliJ IDEA 2017.1.4
My gradle file is following:
group 'org.ks'
version '1.0-SNAPSHOT'
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:1.4.7.RELEASE"
}
}
apply plugin: "org.springframework.boot"
task wrapper(type: Wrapper) {
gradleVersion = '2.4'
}
apply plugin: 'java'
apply plugin: "io.spring.dependency-management"
sourceCompatibility = 1.8
targetCompatibility = 1.8
But the attempt to use #Autowired annotation causes compilation error
package app;
import org.springframework.beans.factory.annotation.Autowired;
public class AutowiredCls {
#Autowired
private int app_name;
}
Compiler marks import and #Autowired as errors (red underline)
application.yml:
app.name = autowired_sample
What do I do wrong?
Please add below dependencies, you can refer to this for more details
dependencies {
// tag::jetty[]
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
}
It doesn't look like your project has any dependencies at all. (I can see that your buildscript has dependencies... but these will not apply to the project sources thamselves.)
Here is a build.gradle file from a project I once generated using https://start.spring.io:
buildscript {
ext {
springBootVersion = '1.3.5.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'spring-boot'
apply plugin: 'war'
war {
baseName = 'soffit-samples'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
configurations {
providedRuntime
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-cache')
compile('org.springframework.boot:spring-boot-starter-web')
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}
The project itself (my sources) contains 2 dependencies defined for the compile scope:
org.springframework.boot:spring-boot-starter-cache
org.springframework.boot:spring-boot-starter-web
Both of these are Spring dependencies. I imagine that one (or both) of these give my sources access to the #Autowired annotation... either directly or transitively (probably transitively).
FYI - I 've found the solution. It's best to visit start.spring.io to generate gradle.
build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'gs-spring-boot'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile('org.springframework.boot:spring-boot-autoconfigure')
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile("junit:junit")
}
gradle.properties:
springVersion=1.5.8.RELEASE

Gradle wsdl generating

I want to generate java files from wsdl. I try to use wsdl2java gradle plugin. I define the plugin:
subprojects {
buildscript{
repositories{
jcenter()
mavenCentral()
}
dependencies {
classpath 'no.nils:wsdl2java:0.10'
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'
apply plugin: 'application'
apply plugin: 'no.nils.wsdl2java'
....
}
but I got this error:
> Plugin with id 'no.nils.wsdl2java:no.nils:wsdl2java' not found.
I checked the syntax (many times it is good). I googled for the plugin, it is used by many people.
Does anybody have an idea what is going wrong?
Upd:
I have a main gradle where the plugins defined, and there are three sub project, where I want to use this plugin.
I defined the sub projects in the settings.gradle:
include 'project1', 'project2', 'project3'
I made a folder and the build.gradle file for each project.
If I commented out the apply plugin: 'no.nils.wsdl2java' in the main build.gradle and the wsdl2java methods in the sub projects the gradle works fine.
You add the buildscript inside the subprojects-closure, thats not supported, see this Gradle discussion (Buildscript {} in subprojects {} ignored?).
You do not have to add the buildscript for every project, it is enough to just declare it on the root-build.gradle
buildscript{
repositories{
jcenter()
mavenCentral()
}
dependencies {
classpath 'no.nils:wsdl2java:0.10'
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'
apply plugin: 'application'
apply plugin: 'no.nils.wsdl2java'
....
}
I was able to get the wsdl2 java working in my gradle build with jaxws and ant tasks. Here it is
apply plugin: 'java'
repositories {
mavenCentral()
flatDir {
dirs 'lib'
}
}
configurations { jaxws }
dependencies { jaxws 'com.sun.xml.ws:jaxws-tools:2.2.6' }
dependencies {
compile 'com.sun.xml.bind:jaxb-impl:2.2.6'
}
task generateSCMOrderImportServiceClient{
if(!file("./lib/employee-services-client.jar").exists()) {
def rootDir = file("build/wsdlToJava/employee-services-client");
def javaDir = file("${rootDir}/java");
def wsdlJarDir = file("${projectDir}/lib");
def classesDir = file("${rootDir}/classes");
def wsdlDir=file("${projectDir}/src/main/resources/wsdl");
def wsdlFile = file("${wsdlDir}/employee-services.wsdl")
doLast{
classesDir.mkdirs()
javaDir.mkdirs()
wsdlJarDir.mkdirs()
copy {
from "${wsdlFile}"
into "${classesDir}"
}
ant {
taskdef(name: 'wsimport',
classname: 'com.sun.tools.ws.ant.WsImport',
classpath: configurations.jaxws.asPath)
wsimport(keep: true,
destdir: classesDir,
sourcedestdir: javaDir,
extension: "true",
verbose: "true",
quiet: "false",
xnocompile: "false",
xendorsed: true,
wsdlLocation: "EmployeeServices.wsdl",
wsdl: "${wsdlFile}")
{
binding(dir:"${wsdlDir}", includes:"jaxb-bindings.xml,jaxws-bindings.xml")
xjcarg(value: "-XautoNameResolution")
}
}
ant.jar(
destfile: wsdlJarDir.path + "/employee-services-client.jar",
basedir: classesDir
)
}
}
}
compileJava.dependsOn generateSCMOrderImportServiceClient
I had achieved this task using this git repository. The build.gradle file looks something like this.
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'no.nils:wsdl2java:0.10'
}
}
plugins {
id 'org.springframework.boot' version '2.2.0.M6'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
id 'no.nils.wsdl2java' version '0.10'
}
group = 'your.application.groupname'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
}
dependencies {
wsdl2java(
'com.sun.xml.bind:jaxb-xjc:2.3.0.1',
'javax.xml.bind:jaxb-api:2.3.1',
'javax.xml.ws:jaxws-api:2.3.1',
'org.apache.cxf:cxf-rt-wsdl:3.2.7',
'javax.jws:javax.jws-api:1.1',
'com.sun.xml.bind:jaxb-core:2.3.0.1',
'com.sun.xml.bind:jaxb-xjc:2.3.2',
'com.sun.xml.bind:jaxb-impl:2.3.2',
'javax.xml.bind:jaxb-api:2.3.1'
)
implementation 'com.sun.xml.bind:jaxb-core:2.3.0.1'
implementation 'com.sun.xml.bind:jaxb-xjc:2.3.0.1'
implementation 'com.sun.xml.bind:jaxb-impl:2.3.2'
implementation 'javax.xml.bind:jaxb-api:2.3.1'
implementation 'javax.xml.ws:jaxws-api:2.3.1'
implementation 'org.apache.cxf:cxf-rt-wsdl:3.2.7'
implementation 'javax.jws:javax.jws-api:1.1'
}
test {
useJUnitPlatform()
}
wsdl2java {
wsdlsToGenerate = [
['-p', 'your.package.name',
'-autoNameResolution', "$projectDir/src/main/resources/wsdl/some_wsdl_file.wsdl"]
]
generatedWsdlDir = file("$projectDir/src/main/java")
wsdlDir = file("$projectDir/src/main/resources/wsdl")
locale = Locale.ENGLISH
}
wsdl2javaExt {
cxfVersion = "2.5.1"
}
To generate the java code we need to run the gradle task as shown below.
$ gradlew wsdl2java
For anybody who is looking for generating with Apache CXF. I tried to avoid using any plugin. I did it by creating configuration with dependencies, externalized array of strings with wsdl file names and then just use it like this:
ext {
wsdlDir = file("${projectDir}/src/main/resources/wsdl")
outputDir = file("$buildDir/generated-sources")
sourceWsdls = [
"$wsdlDir/MyWsdlFile1.wsdl",
"$wsdlDir/MyWsdlFile2.wsdl",
"$wsdlDir/MyWsdlFile3.wsdl",
"$wsdlDir/MyWsdlFile4.wsdl"
]
}
sourceSets.main.java.srcDirs += "$outputDir"
dependencies {
cxf (
'org.apache.cxf:cxf-tools-wsdlto-core:3.3.6',
'org.apache.cxf:cxf-tools-wsdlto-frontend-jaxws:3.3.6',
'org.apache.cxf:cxf-tools-wsdlto-databinding-jaxb:3.3.6'
)
}
task generateJavaClasses {
doLast{
sourceWsdls.each { wsdlFile ->
javaexec {
classpath configurations.cxf
main = 'org.apache.cxf.tools.wsdlto.WSDLToJava'
args '-d', outputDir
args '-b', 'PATH/TO/BINDING/FILE.xjb'
args wsdlFile
}
}
}
}
This is just simple calling javaexec of Apache CXF class - see docs for all args and options.
Note: If you have a folder with wsdl files and you want to generated classes from all wsdl files there, it is even easier and just use it like this:
task generateJavaClassesAllWsdlFiles {
doLast{
// Find all wsdl files in directory defined in ext
fileTree(wsdlDir).matching {
include "*.wsdl"
}.each {
wsdlFile ->
println "Generating " + wsdlFile
javaexec {
classpath configurations.cxf
main = 'org.apache.cxf.tools.wsdlto.WSDLToJava'
args '-d', outputDir
args '-b', 'PATH/TO/BINDING/FILE.xjb'
args wsdlFile
}
}
}
}
I put it all into gist, if you want to see it complete, gist is here.
To solve this try adding the buildScript before the plugin declarations and apply the wsdl plugin after the plugin block for example:
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'no.nils:wsdl2java:0.10'
}
}
plugins {
id 'org.springframework.boot' version '2.1.7.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
id 'war'
id "org.sonarqube" version "2.7"
}
apply plugin: 'java'
apply plugin: 'no.nils.wsdl2java'
for JDK8 you can update gradle with the following and specify cxfVersion under wsdl2java
apply plugin: 'no.nils.wsdl2java'
wsdl2java {
wsdlDir = file("$projectDir/src/main/resources/fooSchemas")
cxfVersion = '3.3.2'
wsdlsToGenerate = [
["$projectDir/src/main/resources/emailSchemas/FooService.wsdl"]
]
}

Categories

Resources