This message was deleted.
# configuration-cache
s
This message was deleted.
c
Try with configuration cache disabled, it's perhaps caching the vpn status.
If that is the case the provider invocation can be moved into the buildcache block
p
Hi Gianfranco, Given this changes the configuration of your build you'll want to run this function on each build invocation and invalidate the configuration cache when its return value change. In order to do this you need to implement a
ValueSource
and use it via
ProviderFactory.of(...)
. See https://docs.gradle.org/current/javadoc/org/gradle/api/provider/ValueSource.html
g
Hi @Paul Merlin. So I ended up with this:
Copy code
interface VpnParameters extends ValueSourceParameters {
    Property<String> getServerUrl();
}

abstract class VpnConnectionSource implements ValueSource<Boolean, VpnParameters> {
    @Override
    Boolean obtain() {
        String serverUrl = getParameters().serverUrl.get()
        return hasServerConnection(serverUrl)
    }

    boolean hasServerConnection(String serverUrl) {
        try (Socket socket = new Socket()) {
            // Logic to check if we have a connection to our VPN
            println "Found VPN connection for $serverUrl"
            return true
        } catch (Exception exception) {
            println "VPN connection not found for $serverUrl (Reason: '${exception.message}')."
            return false
        }
    }
}

String url = "<https://my.vpn.com>"
def vpnProvider = settings.providers.of(VpnConnectionSource.class) {
    parameters {
        serverUrl = url
    }
}

println(vpnProvider.get().class)
boolean remoteCacheEnabled = vpnProvider.get()
println "Remote cache enabled: $remoteCacheEnabled"

buildCache {
    remote(HttpBuildCache) {
        enabled = remoteCacheEnabled
        push = isCi
        url = "$url/cache/"
    }
}
However, when I run
./gradlew :app:assembleDebug
, I'm encountering this error:
Copy code
Found VPN connection for <https://my.vpn.com>
class java.lang.Boolean
Remote cache enabled: true
FAILURE: Build failed with an exception.

* What went wrong:
Gradle could not start your build.
> Could not create service of type BuildCacheController using .createBuildCacheController().
   > HTTP build cache has no URL configured
This error is the same as this one from https://github.com/gradle/gradle/issues/14874. Is this fixed in Gradle 7.5?
p
This issue is about a custom build cache implementation, that's a different thing.
c
HTTP build cache has no URL configured
would seem to indicate that the URL is not being correctly set
p
HTTP build cache has no URL configured
looks weird to me given you have
Copy code
url = "$url/cache/"
Are you sure this is a valid URL to a build cache node?
g
If I change it to this, then it works and I can accesss the remote cache.
Copy code
buildCache {
    remote(HttpBuildCache) {
        enabled = true // Dont use the provider
        push = isCi
        url = "$url/cache/"
    }
}
Copy code
Found VPN connection for <https://my.vpn.com>
class java.lang.Boolean
Remote cache enabled: true

BUILD SUCCESSFUL in 54s
9280 actionable tasks: 129 executed, 336 from cache, 8815 up-to-date
p
aha
g
It seems like the error is only happening when I use the result of
provider.get()
in
buildCache
p
Could you please try moving the creation of the value source inside the
remote(HttpBuildCache) {}
lambda? It's just to rule out something
Like that:
Copy code
buildCache {
    def providers = settings.providers
    remote(HttpBuildCache) {

        String url = "<https://my.vpn.com>"
        def vpnProvider = providers.of(VpnConnectionSource.class) {
            parameters {
                serverUrl = url
            }
        }

        println(vpnProvider.get().class)
        boolean remoteCacheEnabled = vpnProvider.get()
        println "Remote cache enabled: $remoteCacheEnabled"

    
        enabled = remoteCacheEnabled
        push = isCi
        url = "$url/cache/"
    }
}
g
Same error
Copy code
Found VPN connection for <https://my-vpn.com>
class java.lang.Boolean
Remote cache enabled: true

FAILURE: Build failed with an exception.

* What went wrong:
Gradle could not start your build.
> Could not create service of type BuildCacheController using .createBuildCacheController().
   > HTTP build cache has no URL configured
p
Ok
I need to run now. Something is not right. Please open an issue with this reproducer and the team can look at it
Quick question: you get that error on the first build, calculating the task graph? or only on the second build, reusing the configuration cache?
g
It's happening with both the configuration-cache enabled and disabled.
p
🤔
Please also mention this in the issue
g
It's also happening on Gradle 7.5, I'm going to open an issue. Thanks for the support.
Oh wait, I just realized that with your code above it works if the provider's value does not change.
Copy code
buildCache {
    def providers = settings.providers
    remote(HttpBuildCache) {

        String url = "<https://my.vpn.com>"
        def vpnProvider = providers.of(VpnConnectionSource.class) {
            parameters {
                serverUrl = url
            }
        }

        println(vpnProvider.get().class)
        boolean remoteCacheEnabled = vpnProvider.get()
        println "Remote cache enabled: $remoteCacheEnabled"

    
        enabled = remoteCacheEnabled
        push = isCi
        url = "$url/cache/"
    }
I guess there must be a reasonable explanation for that behavior 😅
First build with
./gradlew :app:assembleDebug
and no VPN connection
Copy code
Configuration cache is an incubating feature.
Configuration on demand is an incubating feature.
Calculating task graph as configuration cache cannot be reused because file 'tools/gradle-cache-node-config.gradle' has changed.
VPN connection not found for <https://my.vpn.com> (Reason: 'Connect timed out').
Remote cache enabled: false

BUILD SUCCESSFUL in 1m 4s
9280 actionable tasks: 9280 up-to-date
Configuration cache entry stored.
Second build with
./gradlew :app:assembleDebug
and no VPN connection:
Copy code
Configuration cache is an incubating feature.
Configuration on demand is an incubating feature.
VPN connection not found for <https://my.vpn.com> (Reason: 'Connect timed out').
Reusing configuration cache.

BUILD SUCCESSFUL in 5s
9275 actionable tasks: 9275 up-to-date
Configuration cache entry reused.
Third build with
./gradlew :app:assembleDebug
and connected to the VPN; however, it fails with the same error than before
Copy code
Configuration cache is an incubating feature.
Configuration on demand is an incubating feature.
Found VPN connection for <https://my.vpn.com>
Calculating task graph as configuration cache cannot be reused because a build logic input of type 'VpnConnectionSource' has changed.
Found VPN connection for <https://my.vpn.com>
Remote cache enabled: true

0 problems were found storing the configuration cache.

See the complete report at file:///Users/gianfranco.monzon/Documents/rappi/build/reports/configuration-cache/a4ykle2laqrcw1011gdh200a0/bkc4qjoucgl778cxj19sj43su/configuration-cache-report.html

FAILURE: Build failed with an exception.

* What went wrong:
Gradle could not start your build.
> Could not create service of type BuildCacheController using .createBuildCacheController().
   > HTTP build cache has no URL configured
c
try without configuration on demand, that seems to be a very experimental / problematic feature.
g
Same error without configuration on demand. This is my
gradle.properties
Copy code
# Project-wide Gradle settings
org.gradle.daemon=true
org.gradle.parallel=true
# org.gradle.configureondemand=true
org.gradle.caching=true
org.gradle.jvmargs=-Dfile.encoding=UTF-8 -Xmx8g -Xms4g -XX:+UseParallelGC
org.gradle.unsafe.configuration-cache=true

kotlin.incremental.usePreciseJavaTracking=true
kapt.include.compile.classpath=false
kapt.incremental.apt=true

android.useAndroidX=true
android.enableJetifier=true
android.databinding.incremental=true
android.experimental.cacheCompileLibResources=true
android.experimental.enableSourceSetPathsMap=true

rappi.localBuild=true
rappi.payMocksEnabled=true
c
Did this message go away:
Configuration on demand is an incubating feature.
g
Yes
Copy code
Configuration cache is an incubating feature.
Calculating task graph as configuration cache cannot be reused because file 'gradle.properties' has changed.
VPN connection not found for <https://my.vpn.com> (Reason: 'Connect timed out').
Remote cache enabled: false

BUILD SUCCESSFUL in 34s
9280 actionable tasks: 3 from cache, 9277 up-to-date
Configuration cache entry stored.
Copy code
Configuration cache is an incubating feature.
VPN connection not found for <https://my.vpn.com> (Reason: 'Connect timed out').
Reusing configuration cache.

BUILD SUCCESSFUL in 4s
9275 actionable tasks: 3 from cache, 9272 up-to-date
Configuration cache entry reused.
Copy code
Configuration cache is an incubating feature.
Found VPN connection for <https://my.vpn.com>
Calculating task graph as configuration cache cannot be reused because a build logic input of type 'VpnConnectionSource' has changed.
Found VPN connection for <https://my.vpn.com>
Remote cache enabled: true

0 problems were found storing the configuration cache.

See the complete report at file:///Users/gianfranco.monzon/Documents/rappi/build/reports/configuration-cache/a4ykle2laqrcw1011gdh200a0/bkc4qjoucgl778cxj19sj43su/configuration-cache-report.html

FAILURE: Build failed with an exception.

* What went wrong:
Gradle could not start your build.
> Could not create service of type BuildCacheController using .createBuildCacheController().
   > HTTP build cache has no URL configured
Interesting enough, if I mark eveyrthing as final, then the problem goes away. 🤔
Copy code
final String nodeUrl = "<https://gradle-cache.dev.rappi.com>"

final def vpnProvider = settings.providers.of(VpnConnectionSource.class) {
    parameters {
        serverUrl = nodeUrl
    }
}

final boolean remoteCacheEnabled = vpnProvider.get()
println "Remote cache enabled: $remoteCacheEnabled"

buildCache {
    remote(HttpBuildCache) {
        enabled = remoteCacheEnabled
        push = isCi
        url = "$nodeUrl/cache/"
    }
}
First build without VPN
Copy code
./gradlew :app:assembleDebug
Configuration cache is an incubating feature.
Configuration on demand is an incubating feature.
Calculating task graph as configuration cache cannot be reused because file 'tools/ge/gradle-cache-node-config.gradle' has changed.
VPN connection not found for <https://gradle-cache.dev.rappi.com> (Reason: 'Connect timed out').
Remote cache enabled: false

0 problems were found storing the configuration cache.

See the complete report at file:///Users/gianfranco.monzon/Documents/rappi/build/reports/configuration-cache/a4ykle2laqrcw1011gdh200a0/cxkjktsjf93db8q40gs6s3tn9/configuration-cache-report.html

BUILD SUCCESSFUL in 1m 1s
9280 actionable tasks: 9280 up-to-date
Configuration cache entry stored.
Second build without VPN
Copy code
./gradlew :app:assembleDebug
Configuration cache is an incubating feature.
Configuration on demand is an incubating feature.
VPN connection not found for <https://gradle-cache.dev.rappi.com> (Reason: 'Connect timed out').
Reusing configuration cache.

BUILD SUCCESSFUL in 7s
9275 actionable tasks: 3 from cache, 9272 up-to-date
Configuration cache entry reused.
Third build with VPN
Copy code
./gradlew :app:assembleDebug
Configuration cache is an incubating feature.
Configuration on demand is an incubating feature.
Found VPN connection for <https://gradle-cache.dev.rappi.com>
Calculating task graph as configuration cache cannot be reused because a build logic input of type 'VpnConnectionSource' has changed.
Found VPN connection for <https://gradle-cache.dev.rappi.com>
Remote cache enabled: true

0 problems were found storing the configuration cache.

See the complete report at file:///Users/gianfranco.monzon/Documents/rappi/build/reports/configuration-cache/a4ykle2laqrcw1011gdh200a0/6vueooe9ptz278qk8ui6l7my6/configuration-cache-report.html

BUILD SUCCESSFUL in 27s
9280 actionable tasks: 3 from cache, 9277 up-to-date
Configuration cache entry stored.
Fourth build with VPN (this one went really slow compared to the second build)
Copy code
./gradlew :app:assembleDebug
Configuration cache is an incubating feature.
Configuration on demand is an incubating feature.
Found VPN connection for <https://gradle-cache.dev.rappi.com>
Reusing configuration cache.

BUILD SUCCESSFUL in 49s
9275 actionable tasks: 3 from cache, 9272 up-to-date
Configuration cache entry reused.
Fifth build without VPN to test if everything keeps working and I got this error
Copy code
Starting a Gradle Daemon, 1 busy and 4 stopped Daemons could not be reused, use --status for details
Configuration cache is an incubating feature.
Configuration on demand is an incubating feature.

FAILURE: Build failed with an exception.

* What went wrong:
Gradle could not start your build.
> Cannot create service of type BuildTreeActionExecutor using method LauncherServices$ToolingBuildTreeScopeServices.createActionExecutor() as there is a problem with parameter #1 of type List<BuildActionRunner>.
   > Cannot create service of type BuildModelActionRunner using BuildModelActionRunner constructor as there is a problem with parameter #1 of type PayloadSerializer.
      > Cannot create service of type PayloadSerializer using method LauncherServices$ToolingGradleUserHomeScopeServices.createPayloadSerializer() as there is a problem with parameter #2 of type PayloadClassLoaderFactory.
         > Cannot create service of type PayloadClassLoaderFactory using method LauncherServices$ToolingGradleUserHomeScopeServices.createClassLoaderFactory() as there is a problem with parameter #1 of type CachedClasspathTransformer.
            > Cannot create service of type DefaultCachedClasspathTransformer using DefaultCachedClasspathTransformer constructor as there is a problem with parameter #6 of type FileSystemAccess.
               > Cannot create service of type FileSystemAccess using method VirtualFileSystemServices$GradleUserHomeServices.createFileSystemAccess() as there is a problem with parameter #2 of type VirtualFileSystem.
                  > Cannot create service of type BuildLifecycleAwareVirtualFileSystem using method VirtualFileSystemServices$GradleUserHomeServices.createVirtualFileSystem() as there is a problem with parameter #6 of type GlobalCacheLocations.
                     > Cannot create service of type GlobalCacheLocations using method GradleUserHomeScopeServices.createGlobalCacheLocations() as there is a problem with parameter #1 of type List<GlobalCache>.
                        > Could not create service of type FileAccessTimeJournal using GradleUserHomeScopeServices.createFileAccessTimeJournal().
                           > Timeout waiting to lock journal cache (/Users/gianfranco.monzon/.gradle/caches/journal-1). It is currently in use by another Gradle instance.
                             Owner PID: 36627
                             Our PID: 37151
                             Owner Operation: 
                             Our operation: 
                             Lock file: /Users/gianfranco.monzon/.gradle/caches/journal-1/journal-1.lock
Sixth build without VPN to test if everything keeps working.
Copy code
./gradlew :app:assembleDebug
Starting a Gradle Daemon, 5 stopped Daemons could not be reused, use --status for details
Configuration cache is an incubating feature.
Configuration on demand is an incubating feature.
VPN connection not found for <https://gradle-cache.dev.rappi.com> (Reason: 'Connect timed out').
Calculating task graph as configuration cache cannot be reused because a build logic input of type 'VpnConnectionSource' has changed.
VPN connection not found for <https://gradle-cache.dev.rappi.com> (Reason: 'Connect timed out').
Remote cache enabled: false

0 problems were found storing the configuration cache.

See the complete report at file:///Users/gianfranco.monzon/Documents/rappi/build/reports/configuration-cache/a4ykle2laqrcw1011gdh200a0/xj79okyqfag8uftok0ng1ih3/configuration-cache-report.html

BUILD SUCCESSFUL in 50s
9280 actionable tasks: 3 from cache, 9277 up-to-date
Configuration cache entry stored.
Build is successful, but it did not reuse the configuration cache from the first build when it should have been reused. Is this expected behavior?
p
I think https://github.com/gradle/gradle/issues/20126 could explain why some CC problems were not reported
Build is successful, but it did not reuse the configuration cache from the first build when it should have been reused. Is this expected behavior?
Unfortunately yes, the cache key would be the same but the cache fingerprint invalidates it. That's an interesting case for which the current scheme is counter productive.