Can I add a local file to a configuration?


(Blaine Simpson) #1

As shown in the User Guide, this works to add a generated jar file into the archives configuration:

task myJar(type: Jar)
  artifacts {
    archives myJar
}

But I need to get my local jar file, which is not built directly by Gradle, into my configuration. This, and every other alternative I’ve tried, does not work:

artifacts {
    archives file('tmp/ajar.jar')
}

The straight-forward way would be if the Configuration class had a method to add an element by URL or File or similar, but none. The only thing close to a suitable Dependency or Artifact class that I can find in the Javadocs is the interface org.gradle.api.artifacts.SelfResolvingDependency, but nothing in docs about an implementing class or a hook from the DSL.


(Adam Murdoch) #2

Do you want to include it for publishing, or as a dependency? ie is it an incoming dependency or an outgoing publication?


(Blaine Simpson) #3

Outgoing (for publishing), but not built directly by Gradle. It is built by an Ant task via ant.importBuild().


(Blaine Simpson) #4

I just tried this, attempting to copy what the User Guide does in example 35.11. (You can see that I also tried some alternatives, now commented out, for specifying the file collection, none of which helped).

dependencies {
    //archives fileTree('tmp') {
    //archives files(['tmp/fk.jar']) {
    archives files('tmp') {
        builtBy 'noop'
    }
}

(Blaine Simpson) #5

Since a Jar “type” task can be added to the archives dependencies list, I did my best to get Gradle to accept my own task in the archives dep list in the same way. Unfortunately, the requirements for adding something to the archives dep list seems to be a secret. Here’s what I tried:

task homeGrown {
    inputs.file file('date.txt')
    outputs.files file('tmp/ajar.jar')
    doLast { println 'Growing...' }
}
  task jarIt(type: Jar) {
    from file('stuff')
}
...
artifacts {
    //archives jarIt
    archives homeGrown
}

Unfortunately, though the jarIt task addition works just fine, my non-Jar-type task addition does not:

Cause: Notation is invalid for an artifact! Passed notation=task ':homeGrown'

(Blaine Simpson) #6

Formatting correction. Sure wish this forum had preview capability. Why choose… or create… software that concentrates on candy like graphical emoticons while it sends out spams for each edit attempt because users must edit blindly.