Use gradle to upload jar to local Maven repository

后端 未结 2 814
一个人的身影
一个人的身影 2021-01-12 14:45

This question has been asked several times, but somehow I don\'t get this to work. Gradle is a great tool, but its documentation is anything but great. No examples make it a

相关标签:
2条回答
  • 2021-01-12 14:59

    I suspect the problem is that you are only editing the POM (via pom.project), instead of configuring the actual Maven coordinates used for installation. Try the following instead:

    // best way to set group ID
    group = 'com.example'
    
    install {
        repositories.mavenInstaller {
            // only necessary if artifact ID diverges from project name
            // the latter defaults to project directory name and can be
            // configured in settings.gradle
            pom.artifactId = 'myName' 
            // shouldn't be needed as this is the default anyway
            pom.packaging = 'jar'
        }
    }
    

    PS: The samples directory in the full Gradle distribution contains many example builds, also for the maven plugin.

    0 讨论(0)
  • 2021-01-12 15:01

    Peter N is CORRECT in the comments of the accepted answer, which works, but shouldn't be the accepted answer.

    You should have this in your build.gradle file

    apply plugin: "maven"
    

    Then you can just do a

    $ ./gradlew install
    

    Or use the built-in task

    $ ./gradlew publishToMavenLocal
    

    Both methods install the artifacts in $HOME/.m2/com/example/example/version

    0 讨论(0)
提交回复
热议问题