I’m cross-posting this question from Stack Overflow, where I will shortly offer a bounty on the answer (really need one, 'cause we love this feature and want to use it). →
dependencies - Getting unknown property error when I try to use new Gradle 7 version catalogs - Stack Overflow
I tried to implement the simplest possible example to better understand
Gradle 7 version catalogs. I used ‘gradle init’ to generate a new application,
then I followed the steps presented in this blog post →
Cédric Champeau's blog: Simplified version management with Gradle 7 exactly as I could.
The result, when I tried to import the project into Intellij (and also when I simply ran ‘gradlew test’ at root directory of project) was the error
below. I’m guessing it is more likely that the
feature works and I did something dumb, than the feature is broken. Any
sharp pair of eyes that can help me spot the dumb thing?
ERROR I GOT
A problem occurred evaluating project ‘:app’.
Could not get unknown property ‘testDependencies’ for extension ‘libs’ of type org.gradle.accessors.dm.LibrariesForLibs.
WHAT I DID
- Generate a simple Gradle example app via gradle init, as below:
Select type of project to generate:
1: basic
2: application
3: library
4: Gradle plugin
Enter selection (default: basic) [1..4] 2<RETURN>
Select implementation language:
1: C++
2: Groovy
3: Java
4: Kotlin
5: Scala
6: Swift
Enter selection (default: Java) [1..6] 5<RETURN>
Split functionality across multiple subprojects?:
1: no - only one application project
2: yes - application and library projects
Enter selection (default: no - only one application project) [1..2] 1<RETURN>
Select build script DSL:
1: Groovy
2: Kotlin
Enter selection (default: Groovy) [1..2] 1<RETURN>
Project name (default: stacko):<RETURN>
Source package (default: stacko):<RETURN>
- Add the version catalog definition where they say it should go (exact content as in blog post)
cat <<EOF >gradle/libs.versions.toml
[libraries]
guava = "com.google.guava:guava:30.0-jre"
junit-jupiter = "org.junit.jupiter:junit-jupiter-api:5.7.1"
junit-engine = { module="org.junit.jupiter:junit-jupiter-engine" }
[bundles]
testDependencies = ["junit-jupiter", "junit-engine"]
EOF
- Enable the preview feature
echo "enableFeaturePreview('VERSION_CATALOGS')" >/tmp/stuff
cat settings.gradle >> /tmp/stuff
cp /tmp/stuff settings.gradle
Then I added this line as the last line in my dependencies { } block →
testImplementation(libs.testDependencies)
- Tried to import into Intellij and got the error shown in ERROR I GOT, above.