Excluding transitive dependency does not work for project dependency

I have a multi-project build where I have to exclude a transitive dependency and replace it by a dependency of the same module but a different version. I tried using something like in the example in 51.4.7. Excluding transitive dependencies and did this:

dependencies {
compile project(’:baseproject’) {
exclude group: ‘com.miglayout’
compile ‘com.miglayout:miglayout-javafx:4.2’

But I get the following error:
A problem occurred evaluating project ‘:myproject’.

Could not find method exclude() for arguments [{group=com.miglayout}] on project ‘:baseproject’.

The example in the official docs is this:

dependencies {
compile(“org.gradle.test.excludes:api:1.0”) {
exclude module: ‘shared’

And apart from it not being a project dependency, I don’t see what is different from my code.




This is a syntax issue. The closure in which you are calling exclude is being interpreted as an argument to the project() method, which is incorrect. Should look like so:

compile(project(':baseproject')) {
    exclude group: 'com.miglayout'

Ah, great, thanks!! It works now.

I need some help to excluding XML during CI build. This file should be used only for local development.

Below is the project structure

The file is under the resources of the module.
src -> main -> resources -> ServiceAccounts.xml

I need this file to be invoked only during CI build. Basically it is used only for local development .

I add the below in my build,gradle

exclude ‘ServiceAccounts.xml’ - > it didn’t work.

I am new to gradle build so your thoughts will be helpful