Question

I have a very simple spring-boot (1.0.2) example (based on http://spring.io/guides/gs/rest-service/) using Gradle (1.12) to create a jar file.

I'm trying to build and publish to my local maven repo using either the maven or maven-publish gradle plugins but am getting the error:

Unable to initialize POM pom-default.xml: Failed to validate POM for project ngdc.sample:hello-springboot at /Users/jcc/Documents/stash/hello-springboot/build/poms/pom-default.xml

and don't understand why. version, group, and archivesBaseName are all specified in the build.gradle. A similar project which doesn't rely on SpringBoot works fine.

Can someone suggest what the problem might be?

Thanks!

--john

Was it helpful?

Solution

You might need to ensure that the parent pom or dependency management is specified as well (depends on your configuration, but if you are using the Spring Boot Gradle plugin you probably do need it). Example here: https://github.com/spring-projects/spring-boot/blob/master/spring-boot-integration-tests/spring-boot-gradle-tests/src/test/resources/installer.gradle

install {
    repositories.mavenInstaller {
        pom.project {
          parent { 
            groupId 'org.springframework.boot'
            artifactId 'spring-boot-starter-parent'
            version "${project.bootVersion}"
          }
        }
    }
}

OTHER TIPS

When the Spring Boot Gradle Plugin without dependency versions in the dependency{...} section, the pom is generated without version for Spring Boot etc.

So at the moment it's required to create the relation to the parent pom by yourself for all maven realted tasks parent { groupId 'org.springframework.boot' artifactId 'spring-boot-starter-parent' version "${project.bootVersion}" }

See https://github.com/spring-projects/spring-boot/issues/1716

I meet the same problem here. Thanks @cjstehno, and I will summary my build file here.

1) if you're using maven plugin, the official guide is available for this.

http://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-gradle-plugin.html#build-tool-plugins-gradle-publishing-artifacts-to-a-maven-repository

2) if you're using maven-publish plugin, you can follow scripts below.

Also, because spring boot needs its own package procedure before publish (such as bootRepackage and assemble), So I make publish depends on build task.

buildscript {
    dependencies {
        classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.1.9.RELEASE'
    }
}

apply plugin: 'spring-boot'
apply plugin: 'maven-publish'

group = '<some group id>'
version = '<some version with -SNAPSHOT>'

jar {
    baseName = '<jar base name>'
}

publish.dependsOn build

publishing {
    publications { 
        mavenJar(MavenPublication){ 
            pom.withXml { 
                def parentNode = asNode().appendNode('parent') 
                parentNode.appendNode('groupId','org.springframework.boot') 
                parentNode.appendNode('artifactId','spring-boot-starter-parent') 
                parentNode.appendNode('version','1.1.9.RELEASE') 
            } 
            from components.java 
        } 
    }
}

publishing {
    repositories {
        maven {
            credentials {
                username 'admin'
                password 'admin123'
            }
            url "http://<nexus server>:8081/nexus/content/repositories/snapshots/"
        }
    }
}

This tells me your artifact (jar or war) is being created but the validation of the accompanying pom is failing. For a valid maven artifact you need groupdId, artifactId and version....
Which translate to gradle group, archivesBaseName and version. Make sure you have these three properties set or configured on your artifact and you might get some luck :-)

e.g...
archivesBaseName = 'xcxcxcxc'
group = "com.blah.xxdddd"
version = '#.#.#'
...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top