Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cacheChangingModulesFor 0, 'seconds' is not working as expected #74

Closed
jolivares opened this issue Feb 10, 2016 · 13 comments
Closed

cacheChangingModulesFor 0, 'seconds' is not working as expected #74

jolivares opened this issue Feb 10, 2016 · 13 comments

Comments

@jolivares
Copy link

If I configure a gradle project which depends on a SNAPSHOT library it fails to refresh that dependency even if a use:

configurations.all {
    resolutionStrategy { cacheChangingModulesFor 0, 'seconds' }
}

If I stop using dependency-management-plugin everything works as expected.

Sample build.gradle:

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies { 
        classpath "io.spring.gradle:dependency-management-plugin:0.5.4.RELEASE"
    }
}

repositories {
    jcenter()
    maven {
        url 'https://oss.sonatype.org/content/repositories/snapshots/'
    }
}

configurations.all {
    resolutionStrategy { cacheChangingModulesFor 0, 'seconds' }
}

apply plugin: "io.spring.dependency-management"
apply plugin: 'java'

dependencyManagement {
    resolutionStrategy {
        cacheChangingModulesFor 0, 'seconds'
    }
}

dependencies {
    compile 'org.mongodb:mongo-java-driver:3.3.0-SNAPSHOT'
    testCompile 'junit:junit:4.12'   
}

You can find an attached project
gradle-dep-test.tar.gz

@flozano
Copy link

flozano commented Feb 10, 2016

Maybe related to #38 ?

@flozano
Copy link

flozano commented Feb 10, 2016

I confirmed that, with this plugin enabled, with --refresh-dependencies gradle tries at least to obtain maven-metadata.xml.

@wilkinsona
Copy link
Contributor

@jolivares You haven't marked the mongo-java-driver dependency as changing=true. When I make that change I can see the problem that you've described.

The problem is that the dependency management plugin uses a resolution strategy to apply the managed versions to your projects dependencies. Sadly, Gradle's resolution strategy configuration isn't additive so the plugin's resolution strategy (with its default caching configuration) replaces yours.

Unless things have changed since I last looked, there's no API in Gradle to get hold of any existing resolution strategy and copy over its configuration, i.e. the ResolutionStrategy API is write-only. One solution would be for the plugin to provide a way to switch off its resolution strategy and to give you access to the Action that's passed into ResolutionStrategy.eachDependency.

@flozano
Copy link

flozano commented Feb 10, 2016

@jolivares You haven't marked the mongo-java-driver dependency as changing=true. When I make that change I can see the problem that you've described.

I was thinking a -SNAPSHOT dependency was already changing by default...

@jolivares
Copy link
Author

@wilkinsona As @flozano pointed out, default gradle resolution can handle -SNAPSHOT dependencies as changing. I wonder why this plugin needs to have an explicit changing=true in that dependency.

@wilkinsona
Copy link
Contributor

Sorry, I was wrong about the need for changing=true.

The problem can be reproduced with this script:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'io.spring.gradle:dependency-management-plugin:0.5.4.RELEASE'
    }
}

repositories {
    maven {
        url 'https://oss.sonatype.org/content/repositories/snapshots/'
    }
}

configurations.all {
    resolutionStrategy { cacheChangingModulesFor 0, 'seconds' }
}

apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'

dependencies {
    compile 'org.mongodb:mongo-java-driver:3.3.0-SNAPSHOT'
}

@wilkinsona
Copy link
Contributor

I've tracked the problem down. It's actually due to the configurations that are created when applying Maven exclusions. Apparently, when a dependency is resolved in one configuration with default caching rules, if it's part of another configuration with different caching rules, the rules are ignored. This script illustrates this behaviour:

repositories {
    maven {
        url 'https://oss.sonatype.org/content/repositories/snapshots/'
    }
}

apply plugin: 'java'

configurations {
    alpha
    bravo.resolutionStrategy { cacheChangingModulesFor 0, 'seconds' }
}

dependencies {
    alpha 'org.mongodb:mongo-java-driver:3.3.0-SNAPSHOT'
    bravo 'org.mongodb:mongo-java-driver:3.3.0-SNAPSHOT'
}

When bravo is resolved, I would expect Gradle to check that the mongo-java-driver dependency is up to date. However, that doesn't happen. From a run with --info:

------------------------------------------------------------
Root project
------------------------------------------------------------

alpha
\--- org.mongodb:mongo-java-driver:3.3.0-SNAPSHOT

archives - Configuration for archive artifacts.
No dependencies

bravo
\--- org.mongodb:mongo-java-driver:3.3.0-SNAPSHOT

compile - Compile classpath for source set 'main'.
No dependencies

default - Configuration for default artifacts.
No dependencies

runtime - Runtime classpath for source set 'main'.
No dependencies

testCompile - Compile classpath for source set 'test'.
No dependencies

testRuntime - Runtime classpath for source set 'test'.
No dependencies

If the mongo-java-driver dependency is removed from alpha then the check is made when bravo is resolved:

------------------------------------------------------------
Root project
------------------------------------------------------------

alpha
No dependencies

archives - Configuration for archive artifacts.
No dependencies

bravo
Cached resource Wed Feb 10 16:57:09 GMT 2016 is up-to-date (lastModified: https://oss.sonatype.org/content/repositories/snapshots/org/mongodb/mongo-java-driver/3.3.0-SNAPSHOT/mongo-java-driver-3.3.0-20160210.165709-13.pom).
\--- org.mongodb:mongo-java-driver:3.3.0-SNAPSHOT

compile - Compile classpath for source set 'main'.
No dependencies

default - Configuration for default artifacts.
No dependencies

runtime - Runtime classpath for source set 'main'.
No dependencies

testCompile - Compile classpath for source set 'test'.
No dependencies

testRuntime - Runtime classpath for source set 'test'.
No dependencies

I think this makes sense as you probably don't want different configurations to contain different snapshots. Similarly, if both configurations have caching disabled then the check is only performed once, this time when alpha is resolved.

In short, the plugin needs to be updated to apply the dependencyManagement resolution strategy to the custom configuration that's used when configuring Maven exclusions.

@flozano
Copy link

flozano commented Feb 11, 2016

👍

@wilkinsona
Copy link
Contributor

@jolivares @flozano When you have a moment, please try the latest 0.5.6.BUILD-SNAPSHOT of the plugin. Snapshots are available from https://repo.spring.io/plugins-snapshot.

@wilkinsona wilkinsona added this to the 0.5.6.RELEASE milestone Feb 11, 2016
@jolivares
Copy link
Author

@wilkinsona It seems to be working as expected. Thanks for your quick response.

@jolivares
Copy link
Author

@wilkinsona do you have an estimated date for the release of this fix?

@wilkinsona
Copy link
Contributor

@jolivares 0.5.6.RELEASE is now available from the usual places

@flozano
Copy link

flozano commented Feb 24, 2016

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants