well, I tried to add repositories and classpath for the plugin in initScript block of init.gradle.kts and then tried to apply the plugin in allProjects block like below.
> Plugin with id ‘com.github.jk1.dependency-license-report’ not found.
First of all, this tingles me like why/what would the version-catalog-generator do with another plugin.
could be something related to a bug in their code. used with their latest version but still no luck.
I am kinda stucked (due to my lack of knowledge too)
–
Second, is there any other way without initScript block ? since that block does not let me use variables from outside context. I am totally lost
Why would you use allProjects?
You said you want to apply a settings plugin, not a project plugin.
So you need to use for example beforeSettings { ... }.
And you cannot apply by ID, but you need to apply by class.
The classes added to the initscript block are not available on the classpath of the settings script or project scripts, so the plugin cannot be found by ID.
So apply<VersionCatalogGeneratorPlugin>() is what you want to do to apply it.
Sorry for confusion I created, the next step will be to apply some other plugins company wide like license check etc.. but obv, I am missing the apply by class stuff. Will update the status.
Result : expectedly “Unresolved reference: dev”
This is from init.gradle.kts
initscript {
>>>> Although I already defined below definition and extension above at the beginning of the init.gradle.kts, Obv the classpath again is somewhere else, I can not access them so had to duplicate definition.
val ARTIFACTORY_BASE_URL = "...."
fun RepositoryHandler.corporateRepos(ARTIFACTORY_BASE_URL: String) {
maven {
name = "central"
url = uri("$ARTIFACTORY_BASE_URL/libs-release")
}
maven {
name = "snapshots"
url = uri("$ARTIFACTORY_BASE_URL/libs-snapshot")
}
maven {
name = "gradle-plugin"
url = uri("$ARTIFACTORY_BASE_URL/gradle-plugin")
}
}
repositories {
mavenLocal()
corporateRepos(ARTIFACTORY_BASE_URL)
}
dependencies {
classpath("dev.aga.gradle:version-catalog-generator:2.1.2")
}
}
Result : Unresolved reference: dev
This is from settings.gradle.kts in project. Where I am importing the generate method from the plugin’s helper. import dev.aga.gradle.versioncatalogs.Generator.generate
I had to leave that plugin for a while since license plugin (project plugin) has critical consequences if failed. It was a bit more easier and your help made it work quite fast. thx
Lastly, I guess this is again yet another classpath issue but why I can not use the repository extension function and other variables defined in the init script file’s very top in initScript block ?
I mean
val someValue = "....."
below fails as someValue is not defined.
initScript {
...$someValue ...
}
You should really not use afterEvaluate.
The main “benefit” of afterEvaluate is timing problems, ordering problems, and race conditions.
There are only very rare edge cases where you have to use it, mostly when needing to cooperate with other plugins badly using afterEvaluate.
plugins.
If you have a look at the JavaDoc of plugins. (i.e. getPlugins()), you will learn that you should not use it, but e.g. pluginManager.withPlugin(...) { ... ] and project.apply....
Especially when using withPlugin (or withId) using afterEvaluate should never be necessary, especially not nested twice.
check should be the more appropriate lifecycle task here.
why I can not use the repository extension function and other variables defined in the init script file’s very top in initScript block ?
Same reason you cannot do so in buildscript or plugins blocks in build scripts or settings scripts.
They are extracted and evaluated separately first to determine the dependencies needed to compile the script, so you cannot use anyhting outside the block, because what is outside the block does not exist from the point of view of that block as it is not executed from within that script.
check should be the more appropriate lifecycle task here.
well our packaging system already packaging the test sources separately (some legacy reasons ) and running them in a different way, we are mostly skipping check.
You should really not use afterEvaluate .
The main “benefit” of afterEvaluate is timing problems, ordering problems, and race conditions.
…
Since it’s working I’ve never tought of afterEvaluate phase, but now I will give it a look and try what you offer also.
Lastly, this thread evaluated somewhere else but I learnt a lot. Honestly, the thread broke a lot of false signs towards gradle also.
Thanks for your great patience and helps.
–
removed afterEvaluate and converted to
allProjects {
pluginManager.withPlugin("java") {
... all java options extra license check plugin etc.. apply and configure here.
}
pluginManager.withPlugin("maven-publish") {
... configure internal maven repositories...
}
}
ıf you don’t like this, I am done and gone in tears
Well, if you like it.
It will not compile, but if that is ok for you.
But besides of the type, that seems fine an init script, yeah. allprojects { ... ] is mainly bad in a project build script as that is then cross-project configuration which is quite evil.