Hey there, I'm trying to autoactivate the buildsc...
# community-support
b
Hey there, I'm trying to autoactivate the buildscan on several conditions e.g. if in CI or if explicitly required on command line. Handling the CI part is easy but I wasn't able to overcome the
--scan
condition, the following code fails
Copy code
develocity {
    buildScan {
        termsOfUseUrl.set("<https://gradle.com/help/legal-terms-of-use>")
        termsOfUseAgree.set("yes")
        publishing {
            onlyIf {
                (System.getenv("CI") != null) or gradle.startParameter.isBuildScan
            }
        }
    }
}
with a serialization issue
Copy code
1 problem was found storing the configuration cache.
- Gradle runtime: cannot serialize object of type 'org.gradle.initialization.DefaultSettings', a subtype of 'org.gradle.api.initialization.Settings', as these are not supported with the configuration cache.
  See <https://docs.gradle.org/9.0.0/userguide/configuration_cache_requirements.html#config_cache:requirements:disallowed_types>
Maybe you have more ideas on this ?
Actually, it seems my failed attempts always were declaring variables outside the
develocity
block, declaring
startParameter
within
develocity
seem to fix the serialization issue.
p
AFAIK you also don’t need the startParameter
With this code, you can still use
--scan
to upload a BuildScan:
Copy code
val isCI = providers.environmentVariable("CI").isPresent
publishing {
  onlyIf { isCI }
}
But it is basically our code
πŸ‘† 1
thank you 1
b
I have another question, how can we auto activate the build scan, when the project is synced in intellij, in particular with the new develocity intellij plugin?
v
Do you want that the plugin shows helpful information or do you actually want to enable a build scan in addition?
b
For sure I would like the plugin to show helpful information, like configuration performance (e.g. created tasks metrics, etc), but at this point it's only in the build scan. So I would like to have the build scan automatically enabled when run within IJ.
v
That did not really answer my question
Do you want to enable that the plugin shows helpful information, or do you want additionally to the helpful information in the plugin also publish a web-based build scan?
b
Well what I'm trying to say is : both !
Today the plugin doesn't show enough useful (Gradle 9, and develocity ij plugin 1.0.0)
v
Just asking, because you should not need to enable build scans to get information in the plugin, you just have to have new enough develocity plugin applied or injected by the IDE
If you want to enable build scans during IJ sync, you could check for
idea.sync.active
system property in the
onlyIf
But make sure that you do not agree to the ToS of scans.gradle.org for other people. Some FOSS projects tend to use
onlyIf { true }
and also configuring the ToS agreeing in the build script which is a very bad idea. πŸ™‚
b
Excellent thanks. Do mean instead that this line shouldn't be set ?
Copy code
termsOfUseAgree.set("yes")
v
Depends on your context. If this is for a company-internal Develocity server for example, all good most probably. But if this is for example is for a FOSS project you should definitely never set that. Otherwise I clone your project and execute a build, then my personal data was sent do the Gradle server because you agreed to the ToS on my behalf which I did not allow you to. The Develocity docs also warn you to not do that.
Just the same, the
idea.sync.active
should not be checked in the
onlyIf
for a FOSS project. Otherwise I just open your project in my IDE and suddenly my personal data was uploaded to Gradle servers without my consent.
πŸ‘ 1
Without the ToS agreeing it at least is not that bad because I still need to post my consent, but still it would not be too nice to hang the IDE sync waiting for my response the ToS question
b
This warning should definitely be on the termsOfUse setting. I believe folk do that because the question is not remembered I think
v
Well, its in the docs of it. πŸ™‚ If you think it should be somewhere else, tell them. But also just use common sense. I.e. do you really want to and are allowed to agree to the ToU for everyone getting that file? If the answer is similar to "no", "maybe", or "I don't know", then you should not set it. πŸ™‚ Besides that, you can make Gradle remember it by using an init script in your Gradle user home that agrees to the terms of use for all builds you run or to selected ones.
Something similar to this for example to opt-in for all projects that use that ToU URL:
Copy code
import com.gradle.develocity.agent.gradle.DevelocityConfiguration

initscript {
    repositories {
        gradlePluginPortal()
    }
    dependencies {
        classpath("com.gradle.develocity:com.gradle.develocity.gradle.plugin:+")
    }
}

settingsEvaluated {
    pluginManager.withPlugin("com.gradle.develocity") {
        configure<DevelocityConfiguration> {
            buildScan {
                termsOfUseAgree.convention(termsOfUseUrl.map { if (it == "<https://gradle.com/help/legal-terms-of-use>") "yes" else null })
            }
        }
    }
}