blueberrycarrot
09/26/2024, 12:01 PM$ cat settings.gradle.kts
val properties = java.util.Properties().let {
it.load(java.io.FileReader(settings.rootDir + "/gradle.properties"))
it
}
settings.rootProject.name = properties.getProperty("artifact")
Gradle:
1: unable to resolve class val
@ line 1, column 5.
val properties = java.util.Properties().let {
^
1 error
The .kts file isn't really a Kotlin source file..?Vampire
09/26/2024, 1:08 PMval artifact: String by settings
settings.rootProject.name = artifact
instead of custom Gradle properties parsingPhạm Lam
09/26/2024, 1:47 PMjava.util.Properties to import instead of using full path here
import java.util.Properties
...
val properties = Properties()blueberrycarrot
09/26/2024, 2:05 PMval artifact: String by settingswoow, that's much nicer, thanks!
blueberrycarrot
09/26/2024, 2:13 PMsettings.gradle.kts, because they're all copy/paste and I was trying to avoid it. That is:
project/
a/
b/
settings.gradle.kts-template
And then a/settings.gradle.kts is symlinked to ../settings.gradle.kts-template.
Back to copy/paste... or is there a way for all subprojects to get their name from their gradle.properties without copying the file?Thomas Broyer
09/26/2024, 2:17 PMblueberrycarrot
09/26/2024, 2:20 PMbuild.gradle.kts, but name cannot be set from there, only from settings.gradle.kts ?blueberrycarrot
09/26/2024, 2:22 PMsettings.gradle.kts uses include("...") for all subprojects.blueberrycarrot
09/26/2024, 2:22 PMsettings.gradle.kts just so that it can set its own artifact nameVampire
09/26/2024, 3:21 PMVampire
09/26/2024, 3:21 PMVampire
09/26/2024, 3:22 PMVampire
09/26/2024, 3:22 PMincludeBuild to construct a composite build.Vampire
09/26/2024, 3:23 PMVampire
09/26/2024, 3:25 PM.kts and thus treats it as Groovy DSL file.
Because if I create a Groovy DSL settings script and put in there just val foo = "", I get exactly the error you described:
Settings file '...\showcase\settings.gradle' line: 1
Could not compile settings file '...\showcase\settings.gradle'.
> startup failed:
settings file '...\showcase\settings.gradle': 1: unable to resolve class val
@ line 1, column 5.
val foo = ""
^Vampire
09/26/2024, 3:26 PM...gradle.kts.Vampire
09/26/2024, 3:26 PMblueberrycarrot
09/26/2024, 4:04 PMbut maybe Gradle sees the name of the link target which does not end inthat must be itand thus treats it as Groovy DSL file..kts
blueberrycarrot
09/27/2024, 8:59 AMIf it is just about the project names but you actually want only one big build with all those projects, just define the names for the projects in that one top-level settings scriptNot sure I understand. Are you saying subprojects (subdirectories with their own build script) are not able to control their own artifact names, and they have to be set at the parent settings script?
blueberrycarrot
09/27/2024, 9:02 AMblueberrycarrot
09/27/2024, 9:02 AMVampire
09/27/2024, 9:16 AMNot sure I understand. Are you saying subprojects (subdirectories with their own build script) are not able to control their own artifact names, and they have to be set at the parent settings script?You can control the artifact names in the normal build script, no need for settings script. But you should not do that, as it causes various other quirks. You should usually just make sure that the project name is equal to the artifact name. And that you can control in the settings script that includes the project by including the project with the name you want and then configuring the project dir to be something different if you really want different directory names than artifact names.
Vampire
09/27/2024, 9:16 AMIs that a single build or multiple builds?could be both
blueberrycarrot
09/27/2024, 10:31 AMsettings script that includes the project by including the project with the name you want and then configuring the project dir to be something different if you really want different directory names than artifact namesSo for example, if my monorepo has two directories for the same artifact name:
project/
superlib1/
superlib2/
One produces superlib-1.0.jar , the other superlib-2.0.jar . As you can see, their artifact names should be superlib, not the directory name. You're saying that project/settings.gradle.kts should include both directories and set new project names for them? But, then if you go into superlib1/ and do a gradle jar just for that subproject, what will its jar filename be?Vampire
09/27/2024, 11:48 AMVampire
09/27/2024, 11:48 AMblueberrycarrot
09/27/2024, 11:50 AMsuperlib1 and superlib2, it's just that the artifacts they produce are the same group+artifact, but different versions. It can be done by specifying the jar name in publications config, but you said it's a bad idea?Vampire
09/27/2024, 11:53 AMVampire
09/27/2024, 11:54 AMVampire
09/27/2024, 11:54 AMblueberrycarrot
09/27/2024, 11:55 AMblueberrycarrot
09/27/2024, 11:55 AMblueberrycarrot
09/27/2024, 11:56 AMThomas Broyer
09/27/2024, 12:03 PMblueberrycarrot
09/27/2024, 12:04 PMVampire
09/27/2024, 12:11 PMJust seems like if Gradle allows customization of published artifact names, it should be ok.... no Gradle is extremely flexible in what you can do if you really need to. But that doesn't mean it is a good idea to do so. 🙂
Vampire
09/27/2024, 12:11 PMVampire
09/27/2024, 12:11 PM