Skip to content

Instantly share code, notes, and snippets.

@suztomo
Created October 21, 2020 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suztomo/794c9ab6b0ee28aee4974f5ffc13ee2b to your computer and use it in GitHub Desktop.
Save suztomo/794c9ab6b0ee28aee4974f5ffc13ee2b to your computer and use it in GitHub Desktop.
Gradle platform and enforcedPlatform note

dependencies {
    constraints {
        implementation('com.google.guava:guava:29.0-jre')
    }
    def c = platform('com.google.cloud:libraries-bom:12.1.0')

    // This line lets me use 29.0-jre
    implementation c
    implementation 'com.google.guava:guava'
}
compileClasspath - Compile classpath for source set 'main'.
+--- com.google.cloud:libraries-bom:12.1.0
|    \--- com.google.guava:guava:29.0-android -> 29.0-jre (c)
+--- com.google.guava:guava -> 29.0-jre
|    +--- com.google.guava:failureaccess:1.0.1
|    +--- com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
|    +--- com.google.code.findbugs:jsr305:3.0.2
|    +--- org.checkerframework:checker-qual:2.11.1
|    +--- com.google.errorprone:error_prone_annotations:2.3.4
|    \--- com.google.j2objc:j2objc-annotations:1.3
\--- com.google.guava:guava:29.0-jre (c)

Version keyword in constraints

dependencies {
    constraints {
        implementation('com.google.guava:guava') {
            version('29.0-jre')
        }
    }
    def c = platform('com.google.cloud:libraries-bom:12.1.0')

    // This line lets me use 29.0-jre
    implementation c
    implementation 'com.google.guava:guava'
}

The version clause was incorrectly used?

compileClasspath - Compile classpath for source set 'main'.
+--- com.google.cloud:libraries-bom:12.1.0
|    \--- com.google.guava:guava:29.0-android (c)
+--- com.google.guava:guava -> 29.0-android
|    +--- com.google.guava:failureaccess:1.0.1
|    +--- com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
|    +--- com.google.code.findbugs:jsr305:3.0.2
|    +--- org.checkerframework:checker-compat-qual:2.5.5
|    +--- com.google.errorprone:error_prone_annotations:2.3.4
|    \--- com.google.j2objc:j2objc-annotations:1.3
\--- com.google.guava:guava -> 29.0-android (c)

Constraints with require

dependencies {
    constraints {
        implementation('com.google.guava:guava') {
            version {
                require '29.0-jre'
            }
        }
    }
    def c = enforcedPlatform('com.google.cloud:libraries-bom:12.1.0')

    // This line lets me use 29.0-jre
    implementation c
    implementation 'com.google.guava:guava'
}

The require is weaker than enforcedPlatform.

compileClasspath - Compile classpath for source set 'main'.
+--- com.google.cloud:libraries-bom:12.1.0
|    \--- com.google.guava:guava:29.0-android (c)
+--- com.google.guava:guava -> 29.0-android
|    +--- com.google.guava:failureaccess:1.0.1
|    +--- com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
|    +--- com.google.code.findbugs:jsr305:3.0.2
|    +--- org.checkerframework:checker-compat-qual:2.5.5
|    +--- com.google.errorprone:error_prone_annotations:2.3.4
|    \--- com.google.j2objc:j2objc-annotations:1.3
\--- com.google.guava:guava:29.0-jre -> 29.0-android (c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment