Unable to publish to local maven repo when using Gradle and Spring Boot

前端 未结 4 1037
忘了有多久
忘了有多久 2021-01-02 08:09

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

相关标签:
4条回答
  • 2021-01-02 08:31

    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

    0 讨论(0)
  • 2021-01-02 08:34

    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.xxffffdd"
    version = '#.#.#'
    ...

    0 讨论(0)
  • 2021-01-02 08:46

    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/"
            }
        }
    }
    
    0 讨论(0)
  • 2021-01-02 08:51

    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}"
              }
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题