0

To install sources to local Maven repository, I was taught to write

apply plugin: "maven-publish"

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

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

          artifact sourceJar {
            classifier "sources"
          }
        }
     }
}

and it copies files as required. Now I wish this work automatically along with install task of maven plugin.

I tried several lines like

install.dependsOn(publishing.publishSources)

or

install.dependsOn(publishSources)

but failed with various errors.

Community
  • 1
  • 1
Dims
  • 47,675
  • 117
  • 331
  • 600
  • Did you try `install.dependsOn(publishToMavenLocal)` ? BTW, why do you need tasks `install` and `publish...` at the same time? – Vyacheslav Shvets Mar 21 '17 at 15:17
  • I have 2 projects, I want second one see both library and it's source (to trace while debug). Otherwise it does decompile or requires setting path to sources all the time manually. If it sees them in maven it just uses them. – Dims Mar 22 '17 at 13:03

1 Answers1

0

You could use the nebula.source-jar plugin. Or you could at least copy/paste the bolierplate from the readme.

Eg: Eliminates this boilerplate:

tasks.create('sourceJar', Jar) {
    dependsOn tasks.classes
    from sourceSets.main.allSource
    classifier 'sources'
    extension 'jar'
    group 'build'
}
publishing {
    publications {
        nebula(MavenPublication) { // if maven-publish is applied
            artifact tasks.sourceJar
        }
        nebulaIvy(IvyPublication) { // if ivy-publish is applied
            artifact tasks.sourceJar
        }
    }
}
lance-java
  • 25,497
  • 4
  • 59
  • 101