Add dependency to custom JAR in current project


(Nick) #1

I’m creating a custom JAR from a custom sourceSet in my project, like so:

task customJar(type: Jar) {
    classifier = 'custom'
    from sourceSets.custom.output
}

Now, I’d like for the project that is defining this task to depend on this JAR at runtime, so it’s reflected in the generated POM’s dependencies. I’ve tried to add it as a dependency like so:

dependencies {
    runtime files(customJar.outputs.files.getFiles())
}

Even then, I have to manually add an entry to the POM file for the custom JAR.

Is there a better way to have Gradle do this for me automatically?

Also, how can I control what dependencies are listed in the POM for the custom JAR? I’m currently adding it to the archives configuration so Maven publishes it when I do an install / uploadArchives. Are there any examples of adding a custom configuration so install / uploadArchives works with both the ‘archives’ and a custom configuration?