cognitio
cognitio

Reputation: 691

How to avoid fetching the source jar from a flatDir dependency with Gradle

I have a Gradle build script, with mixed Maven dependencies (I use Maven Central for dependencies resolution) and a local directory. The snippet is this:

repositories {
    mavenCentral()

    flatDir name: 'directoryRepository', dirs: 'tools/libs'
}

Then I need to declare my local dependencies this way:

dependencies {
    compile ":commons-cli:1.0@jar"
}

I cannot use the files('...') notation (because other parts of the script would fail with a class cast exception from Array to HashMap, and I cannot change that part).

The jar files are added to the build path correctly. The problem is that Gradle wants to fetch, for every jar in the 'tools/libs', another '-source' jar. Indeed, if I have in the tools/libs folder:

commons-cli-1.0.jar
commons-cli-1.0-sources.jar

all works fine. If I remove the source jar, it gives the error "unable to resolve dependency", poiting out the -source jar.

I have more then 50 files to be managed this way, and of course I haven't the source jars (nor I'm interested to have).

How can I exclude the source jar fetching?

Many thanks in advance for any hints.

Fabio Da Soghe

Upvotes: 2

Views: 2733

Answers (1)

rodion
rodion

Reputation: 15029

If you are using IDEA there's a module-wide setting ideaModule.downloadSources = false which can help, but it will disable all source downloading for IDEA.

Not sure what you meant by files(...) notation, but how about trying this?:

dependencies{
  ...
  compile fileTree( dir: "toos/lib", include: '*.jar' )
  ... or ...
  compile fileTree( dir: "toos/lib", includes: ['*.jar'] )
}

Edit:

There appears to be an associated bug report, fixed in milestone 5. Giving it a try revealed that the error is still there but now it's just a warning and the build will succeed. Apparently the warning is coming from Ivy so there is no easy fix for it :(

Upvotes: 3

Related Questions