Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
389 views
in Technique[技术] by (71.8m points)

java - How to publish source into local maven repository with Gradle?

I am developing two related project. One of which is "helper" one and another is "main" one. I am constantly updating "main", but from time to time I am also updating "helper" one. After then I am running install goal in gradle's maven plugin and get jars in local maven repo. After that I do gradle update in "main" project and have updated jars linked.

There are two questions.

1) If staying with maven plugin, then how to publish source code into local maven repo too?

2) Can I do similar without maven plugin, staying only with Gradle?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It's easy to publish sources with the "maven-publish" plugin:

apply plugin: "maven-publish"

task sourceJar(type: Jar) {
  from sourceSets.main.allJava
}

publishing {
    publications {
        mavenJava(MavenPublication) {
          from components.java

          artifact sourceJar {
            classifier "sources"
          }
        }
     }
}

Then go publish to local maven run: gradle publishToMavenLocal

More info in the docs: https://docs.gradle.org/current/userguide/publishing_maven.html#gsc.tab=0


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...