Excluding Transitive Dependencies

The Users’ Guide, Section 23.4.7 indicates that I might exclude a transitive dependency this way:

dependencies {
    compile("org.gradle.test.excludes:api:1.0") {
        exclude module: 'shared'
    }
}

Yet when I try basically the identical thing:

dependencies {
...
        compile('org.springframework:spring-context:4.1.6.RELEASE')
        {
                // Exclude Commons Logging in favor of log4j2 
                exclude module 'commons-logging'
        }
}

the build fails with the following error:

> Could not find method compile() for arguments [org.springframework:spring-context:4.1.6.RELEASE, build_830k5onel2vf9qsa5q2e9kr84$_run_closure4$_closure6@4eaecfd8] on root project 'genesyssmsaccess'.

This error goes away if I remove the closure after the compile statement.

What’s the problem here? I’m using gradle 2.11, same as Users’ Guide.

Did you intentionally exclude the colon from your example?

I can’t imagine how missing that could result in that compile error, but it won’t be the first (or last) bizarre error message coming from a seemingly unrelated issue.

Yes, that was it! It didn’t work but that’s because another dependency depended on it, which means I can just skip the whole exclusion business.