Hello guys, I’ve finished my buildSrc to build-log...
# gradle
g
Hello guys, I’ve finished my buildSrc to build-logic + versions catalog migration, but I’ve a little problem 😒, more in thread.
I need to have this configuration:
Copy code
versionCatalogs {
   	 create("libs") {
        from(files("../gradle/libraries.versions.toml"))
    }
}
Both in my *build-logic/*`settings.gradle` and *project/*`settings.gradle` other wise I can’t have access to my catalog... I have no idea why because I’ve created a simple project from 0 with minimal setup and it works perfectly (just like in google sample settings1 and settings2). Another issue I’m facing is with the
.toml
file name. As you can see it’s called libraries and not libs because if it is libs it will throw the “already existis a catalog with that name” error (again, working as expected in the sample created from scratch). I’m a bit lost here, things are working but feeling hacky. Any hint? Thanks again 🙏
j
libs.version.toml
is added by default
but with
buildSrc
you would need to add those lines too, at the end I think the only settings which is able to get that file by default is the root one because it looks for
gradle/libs.versions.toml
. So if you want that behavior in the rest of projects that have a settings file, you would need to duplicate that file to be in a
gradle/libs.version.toml
respect to that settings file, which is not a good approach.
g
libs.version.toml
is added by default
this means i just need to create the file and skip the gradle versionCatalogs setup? In the google sample they manage to make it work only by using the
versionCatalogs
setup in the *build-logic/*`settings.gradle` and it’s accessible in all the project modules. I’ve achieved the same from the quick sample i’ve created from 0. I’m facing this problem in a project that i’ve migrated to this setup (buildSrc is removed at this point), dunno if could be some caches or strange ghost configurations… 🤔
j
yes, but it will not work un included builds, only in the main project
build-logic is a included build so as I said, it can't find the catalog in
gradle/libs.versions.toml
so you have to indicate it manually with
../gradle/libs.versions.toml
g
inside the build-logic
settings.gradle
that makes sense, but why do i need to add that also to the project settings? since it has
includeBuild("build-logic")
shouldn’t be smart to get it from it? 🤔
build-logic, `settings.gradle`:
Copy code
@file:Suppress("UnstableApiUsage")

enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
    }
    versionCatalogs {
        create("libs") {
            from(files("../gradle/libraries.versions.toml"))
        }
    }
}

include(":conventions")
this makes total sense ^ I’m struggling with this: project
settings.gradle
Copy code
pluginManagement {
    includeBuild("build-logic")
    repositories {
        google()
        gradlePluginPortal()
        mavenCentral()
    }
}

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }

   //if i don't add this it can't find "libs"
    versionCatalogs {
        create("libs") {
            from(files("./gradle/libraries.versions.toml"))
        }
    }
}
in the quick sample from scratch i could make it work, but not on the migrated project:
j
catalogs are not shared because a included build is using it, root project doesn't need it because it should already have it by default, with or without included builds
g
Makes sense. Thing is, I don’t know what am I doing wrong in my setup to receive a
org.gradle.internal.exceptions.LocationAwareException:
upon commenting the
versionCatalogs
from my project
settings.gradle
😞
j
is your project open source?
g
Is not, but i’ll try to remove everything i can from it and share a small portion of it that replicates the problem
could it be cache/temp files problems? 🤔
Copy code
Caused by: ScriptCompilationException(errors=[ScriptCompilationError(message=Unresolved reference: libs, location=/Users/guilhermedelgado/.gradle/.tmp/gradle-kotlin-dsl-5296176479961038049.tmp/build.gradle.kts (7:19)), ScriptCompilationError(message=Unresolved reference: libs, location=/Users/guilhermedelgado/.gradle/.tmp/gradle-kotlin-dsl-5296176479961038049.tmp/build.gradle.kts (8:19)), ScriptCompilationError(message=Unresolved reference: libs, location=/Users/guilhermedelgado/.gradle/.tmp/gradle-kotlin-dsl-5296176479961038049.tmp/build.gradle.kts (9:19)), ScriptCompilationError(message=Unresolved reference: libs, location=/Users/guilhermedelgado/.gradle/.tmp/gradle-kotlin-dsl-5296176479961038049.tmp/build.gradle.kts (10:19)), ScriptCompilationError(message=Unresolved reference: libs, location=/Users/guilhermedelgado/.gradle/.tmp/gradle-kotlin-dsl-5296176479961038049.tmp/build.gradle.kts (11:19))])
	at org.gradle.kotlin.dsl.support.KotlinCompilerKt.compileKotlinScriptModuleTo(KotlinCompiler.kt:187)
	at org.gradle.kotlin.dsl.support.KotlinCompilerKt.compileKotlinScriptToDirectory(KotlinCompiler.kt:148)
	at org.gradle.kotlin.dsl.execution.ResidualProgramCompiler$compileScript$1.invoke(ResidualProgramCompiler.kt:708)
	at org.gradle.kotlin.dsl.execution.ResidualProgramCompiler$compileScript$1.invoke(ResidualProgramCompiler.kt:85)
	at org.gradle.kotlin.dsl.provider.StandardKotlinScriptEvaluator$InterpreterHost$runCompileBuildOperation$1.call(KotlinScriptEvaluator.kt:162)
	at org.gradle.kotlin.dsl.provider.StandardKotlinScriptEvaluator$InterpreterHost$runCompileBuildOperation$1.call(KotlinScriptEvaluator.kt:159)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:199)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73)
	at org.gradle.kotlin.dsl.provider.StandardKotlinScriptEvaluator$InterpreterHost.runCompileBuildOperation(KotlinScriptEvaluator.kt:159)
	at org.gradle.kotlin.dsl.execution.Interpreter$compile$1$1$1$1.invoke(Interpreter.kt:326)
	at org.gradle.kotlin.dsl.execution.Interpreter$compile$1$1$1$1.invoke(Interpreter.kt:72)
	at org.gradle.kotlin.dsl.execution.ResidualProgramCompiler.compileScript-C5AE47M(ResidualProgramCompiler.kt:707)
	at org.gradle.kotlin.dsl.execution.ResidualProgramCompiler.compileStage1-EfyMToc(ResidualProgramCompiler.kt:690)
	at org.gradle.kotlin.dsl.execution.ResidualProgramCompiler.compileStage1-EfyMToc$default(ResidualProgramCompiler.kt:686)
	at org.gradle.kotlin.dsl.execution.ResidualProgramCompiler.emitEval(ResidualProgramCompiler.kt:215)
	at org.gradle.kotlin.dsl.execution.ResidualProgramCompiler.emit(ResidualProgramCompiler.kt:190)
	at org.gradle.kotlin.dsl.execution.ResidualProgramCompiler.emit(ResidualProgramCompiler.kt:182)
	at org.gradle.kotlin.dsl.execution.ResidualProgramCompiler.access$emit(ResidualProgramCompiler.kt:85)
	at org.gradle.kotlin.dsl.execution.ResidualProgramCompiler$emitStaticProgram$1$1.invoke(ResidualProgramCompiler.kt:111)
	at org.gradle.kotlin.dsl.execution.ResidualProgramCompiler$emitStaticProgram$1$1.invoke(ResidualProgramCompiler.kt:85)
	at org.gradle.kotlin.dsl.execution.ResidualProgramCompiler$overrideExecute$1.invoke(ResidualProgramCompiler.kt:534)
	at org.gradle.kotlin.dsl.execution.ResidualProgramCompiler$overrideExecute$1.invoke(ResidualProgramCompiler.kt:85)
	at org.gradle.kotlin.dsl.support.bytecode.AsmExtensionsKt.method(AsmExtensions.kt:131)
	at org.gradle.kotlin.dsl.support.bytecode.AsmExtensionsKt.publicMethod(AsmExtensions.kt:114)
	at org.gradle.kotlin.dsl.support.bytecode.AsmExtensionsKt.publicMethod$default(AsmExtensions.kt:111)
	at org.gradle.kotlin.dsl.execution.ResidualProgramCompiler.overrideExecute(ResidualProgramCompiler.kt:533)
	at org.gradle.kotlin.dsl.execution.ResidualProgramCompiler.access$overrideExecute(ResidualProgramCompiler.kt:85)
	at org.gradle.kotlin.dsl.execution.ResidualProgramCompiler$emitStaticProgram$1.invoke(ResidualProgramCompiler.kt:110)
	at org.gradle.kotlin.dsl.execution.ResidualProgramCompiler$emitStaticProgram$1.invoke(ResidualProgramCompiler.kt:85)
	at org.gradle.kotlin.dsl.execution.ResidualProgramCompiler$program$3.invoke(ResidualProgramCompiler.kt:668)
	at org.gradle.kotlin.dsl.execution.ResidualProgramCompiler$program$3.invoke(ResidualProgramCompiler.kt:85)
	at org.gradle.kotlin.dsl.support.bytecode.AsmExtensionsKt.publicClass-7y5yvvE(AsmExtensions.kt:39)
	at org.gradle.kotlin.dsl.execution.ResidualProgramCompiler.program-5oOsWEo(ResidualProgramCompiler.kt:666)
	at org.gradle.kotlin.dsl.execution.ResidualProgramCompiler.access$program-5oOsWEo(ResidualProgramCompiler.kt:85)
	at org.gradle.kotlin.dsl.execution.ResidualProgramCompiler.emitStaticProgram(ResidualProgramCompiler.kt:796)
	at org.gradle.kotlin.dsl.execution.ResidualProgramCompiler.compile(ResidualProgramCompiler.kt:101)
	at org.gradle.kotlin.dsl.execution.Interpreter$compile$1.invoke(Interpreter.kt:330)
hum guess, not, deleted everything, same problem
in the sample I have access to this info, but in the project i get a “nothing to show” message, could it be a symptom? 🤔
j
sorry, if you publish it I can try to clone to check it out, but so I don't know why you are having this issue
g
Here’s a sample 🙂 I’ve deleted basically everything from the project leaving a MainActivity and the gradle setup.
If you comment project’s
settings.gradle
versionCatalogs you’ll get the same output
Copy code
org.gradle.internal.exceptions.LocationAwareException: Build file '…/sample/build.gradle.kts' line: 7
Script compilation errors:

  Line 07:         classpath(libs.gradle.android.tools)
                             ^ Unresolved reference: libs

 …
i’ve created a new project and imported the “good” build-logic from the one i created from scratch and now everything is working fine 🤷‍♂️
feels like some kind of metadata that could be mixing things up but i don’t know what
j
Hey, sorry I totally forget it, I have a long day, if I can't today I will try tomorrow
Ah, that is great :)
g
no problem Javier, thanks for your time 🙂
I do have a strange behaviour which is this warning:
Copy code
Settings file '/Users/…/build-logic/settings.gradle.kts' line: 9

Using dependency catalogs requires the activation of the matching feature preview.
See the documentation at <https://docs.gradle.org/7.1/userguide/platforms.html#sub:central-declaration-of-dependencies>

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
but everything works fine 🤷
j
Which Gradle version are you using?
g
Copy code
wrapper 7.4.2-all.zip
android tools = "7.2.1"
but for some reason I see this:
but i don’t import 7.1 anywhere 🤔
j
that can be an old version, remove it and rebuild
are you getting that issue from cli or idea sync
g
yup i do that, i remove that folder and after a build there she is
IDE
j
check always via cli, IDE issues can be wrong some times
522 Views