1

I have two projects defined in Gradle, projectA and projectB defined as a multiproject.

ProjectA has a dependency with spring1-beans.jar meanwhile ProjectB has a dependency with ProjectA.

The problem I got is that ProjectB has also a dependency with spring3-beans therefore I need to exclude the Spring1 jar, otherwise it will use the incorrect version of Spring.

The Gradle conf file for ProjectA looks like:

dependencies {
    compile files('lib/spring-beans.jar')
}

and the conf for ProjectB:

dependencies {

    compile project(':projects:projectA') {
        exclude files('lib/spring-beans.jar')
    }
}

Unfortunately, this does not work. Gradle throws the following error:

Could not find method exclude() for arguments [file collection] on project

I have also tried with module with a similar output:

The description 'lib/spring-beans.jar' is invalid

Notes:

  • I am using JARs dependencies because the project is being migrated from Ant, so I cannot switch to a remote repository even though I am opened to suggestions.
Opal
  • 81,889
  • 28
  • 189
  • 210
Jonathan Naguin
  • 14,526
  • 6
  • 46
  • 75
  • I don't know how to exclude this transitive dependency but now you configured to *exclude* closure on *project* instance. It should be `compile(project(':projects:projectA')) {exclude files('lib/spring-beans.jar') }` to configure it for `configuration` (note the parens). Why don't you switch to remote repository? Why it's not possible? – Opal Mar 13 '15 at 09:26
  • @Opal I tried with the parenthesis, but no luck. I cannot use a remote repo for now because it would required changes to the build system and we would like to made the migration by phases. So the first phase is with not remote repos... – Jonathan Naguin Mar 13 '15 at 13:28
  • I meant that the syntax I mentioned fixes this error: *Could not find method exclude() for arguments [file collection] on project*, not excludes the dependency. – Opal Mar 13 '15 at 13:29

1 Answers1

0

I recently saw a similar issue with my Android Gradle build. Here's the issue:

java.io.IOException: Invalid argument
Could not normalize path for file 'C:\Users\xxxxxx\AndroidStudioProjects\FightClub\app\libs\*.jar'.

Here's a snip from the Gradle file:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])  <----  USE THIS
    compile project(':LibQSM')
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.stripe:stripe-android:+'
    compile 'net.hockeyapp.android:HockeySDK:3.5.0'
    compile 'com.joanzapata.pdfview:android-pdfview:1.0.+@aar'
    compile 'com.google.android.gms:play-services-gcm:7.0.0'
    compile files('libs/*.jar') <---- NOT THIS, PROBLEM HERE!!!!!
}

The issue turned out to be the way I was specifying the path for the dependencies. The indicated problem line contained the '/' delimiter, which broke on Windows but worked fine on OSX & Linux.

Be sure that you use the first method shown... 'compile fileTree(dir: 'xxx', include: ['*.jar'])' over the second.

Dan Devine
  • 859
  • 1
  • 8
  • 19