Colton Idle
12/22/2024, 11:35 PMapply(from = rootPoroject.file("scripts/blah.gradle.kts")
and then in my blah.gradle.kts (for testing purposes) I put a println
in there, but I never actually see it printed. am I missing something on how to do this?Vampire
12/23/2024, 2:10 AMbuildSrc
or an included build, for example implemented as precompiled script plugin. Then apply that in your your project.Colton Idle
12/23/2024, 2:05 PMColton Idle
12/23/2024, 2:06 PMVampire
12/23/2024, 2:44 PMbuildSrc
(cannot imagine why) then use an included build, yeah (which I prefer anyway).
But nowadays the differences between the two are rather subtle.Colton Idle
12/23/2024, 3:07 PMVampire
12/23/2024, 4:27 PMbuildSrc
.
If you load one plugin in the root project build script classpath and the other in a subproject build script classpath,
they are also in different class loaders and one can see the other but the other not the one.
Or if you load one plugin in the settings script classpath and the other in a build script classpath,
they are also in different class loaders and one can see the other but the other not the one.
Using an included build might bear less surprises than buildSrc
as buildSrc
stuff is in a separate class loader that is the parent of the root build script class loader,
while the included build is in the classpath and thus class loader where it is used from like any other plugin.
But as I just described, such things can still happen, just like they can happen even without using any buildSrc
or included build.Colton Idle
12/26/2024, 11:45 PMbuildConfigField("String", "XYZ1", getProperty("KEY1"))
buildConfigField("String", "XYZ2", getProperty("KEY2"))
buildConfigField("String", "XYZ3", getProperty("KEY3"))
buildConfigField("String", "XYZ4", getProperty("KEY4"))
...
if I want to just do that snippet of code in another file how would i do that? is that a good enough reason to use legacy script plugins, or should i also go down the route of a convention plugin?Vampire
12/26/2024, 11:47 PMColton Idle
12/26/2024, 11:57 PMVampire
12/27/2024, 12:03 AMVampire
12/27/2024, 12:04 AMColton Idle
12/27/2024, 12:07 AMVampire
12/27/2024, 12:10 AMVampire
12/27/2024, 12:10 AMwhatever.gradle
or whatever.gradle.kts
files you put to buildSrc
or an included buildColton Idle
12/27/2024, 12:12 AMColton Idle
12/27/2024, 12:13 AMVampire
12/27/2024, 12:19 AMVampire
12/27/2024, 12:20 AMColton Idle
12/27/2024, 4:57 PMColton Idle
12/27/2024, 5:14 PMColton Idle
12/27/2024, 5:14 PMplugins {
`kotlin-dsl` // Enables Kotlin precompiled scripts
}
repositories {
mavenCentral()
google()
}
Colton Idle
12/27/2024, 5:14 PMrootProject.name = "buildConfigFieldSetup"
Colton Idle
12/27/2024, 5:15 PMincludeBuild("buildConfigFieldSetup")
Colton Idle
12/27/2024, 5:15 PMVampire
12/27/2024, 5:19 PMgradlePluginPortal()
as dependency.
But other than that, it should be a sufficient setup to start with, yes.
As I said, not too much effort :-)Colton Idle
12/27/2024, 5:32 PMinclude build should be within plugin management block if it is about a plugin.All I want to do is have buildConfigField("String", "XYZ1", getProperty("KEY1")) buildConfigField("String", "XYZ2", getProperty("KEY2")) buildConfigField("String", "XYZ3", getProperty("KEY3")) buildConfigField("String", "XYZ4", getProperty("KEY4")) Are you saying my root settings.gradle.kts should be
rootProject.name = "MyProject"
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
pluginManagement {
repositories {
maven("<https://maven.pkg.jetbrains.space/public/p/compose/dev>")
google()
gradlePluginPortal()
mavenCentral()
}
includeBuild("buildConfigFieldSetup")
}
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven("<https://maven.pkg.jetbrains.space/public/p/compose/dev>")
}
}
include(":app")
OR
rootProject.name = "MyProject"
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
pluginManagement {
repositories {
maven("<https://maven.pkg.jetbrains.space/public/p/compose/dev>")
google()
gradlePluginPortal()
mavenCentral()
}
}
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven("<https://maven.pkg.jetbrains.space/public/p/compose/dev>")
}
}
include(":app")
includeBuild("buildConfigFieldSetup")
Vampire
12/27/2024, 5:39 PMbuildConfigFieldSetup
is a build where you build a plugin to be used in your main build, so you should do the includeBuild
within pluginManagement { ... }
.
What the plugin you build there does and how it is implemented is not relevant.
It also works outside as that is what was there before, as long as you do not build a settings plugin, but it is cleaner to also do it within the pluginManagement
block for project plugins.Vampire
12/27/2024, 5:39 PMColton Idle
12/27/2024, 5:49 PMColton Idle
12/27/2024, 5:55 PMplugins {
`kotlin-dsl`
alias(libs.plugins.androidApplication) <----- error
// or
// id("com.android.application") <---- this errors too. Hmm
}
repositories {
mavenCentral()
google()
}
android {
buildConfigField("String", "XYZ1", getProperty("KEY1"))
}
Vampire
12/27/2024, 6:22 PMplugins
block, but not inside.
You indeed need the id
one, but you missed to add a dependency to that plugin in buildConfigFieldSetup/build.gradle.kts
.Vampire
12/27/2024, 6:23 PMbuildConfigFieldSetup/build.gradle.kts
?Vampire
12/27/2024, 6:24 PMbuildConfigField
lines there makes no sense at all.
That is the build script to build your plugins.
You want to do that in a plugin which you then apply to your main build.
The plugin is built by the included build and then applied, doing its actions.Colton Idle
12/27/2024, 6:38 PMapply(from = rootPoroject.file("scripts/blah.gradle.kts")
Vampire
12/27/2024, 7:07 PMsrc/main/kotlin
.
Why going the strongly discouraged way if you are almost there the proper way?Vampire
12/27/2024, 7:08 PMColton Idle
12/27/2024, 7:18 PMColton Idle
12/27/2024, 7:18 PM