Hi guys! First time here, I just learning Java and...
# community-support
l
Hi guys! First time here, I just learning Java and a bit of gradle. I am doing a project for uni but I am not being able to build the project using gradle.build. I am getting the following error:
A problem occurred evaluating project ':app'.
Could not get unknown property 'libs' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
I am not sure what I should do. Could you guys help me? This is my
build.gradle
file:
Copy code
/*
 * This file was generated by the Gradle 'init' task.
 *
 * This generated file contains a sample Java application project to get you started.
 * For more details on building Java & JVM projects, please refer to <https://docs.gradle.org/8.8/userguide/building_java_projects.html> in the Gradle documentation.
 */

plugins {
    // Apply the application plugin to add support for building a CLI application in Java.
    id 'application'
}

task myJavadocs(type: Javadoc) {
    source = sourceSets.main.allJava
}

repositories {
    // Use Maven Central for resolving dependencies.
    mavenCentral()
}

dependencies {
    // Use JUnit Jupiter for testing.
    testImplementation libs.junit.jupiter

    testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

    // This dependency is used by the application.
    implementation libs.guava

    implementation 'javax.xml.bind:jaxb-api:2.3.1'
    implementation 'org.glassfish.jaxb:jaxb-runtime:2.3.1'
}

// Apply a specific Java toolchain to ease working on different environments.
java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(21)
    }
}

application {
    // Define the main class for the application.
    mainClass = 'cabbieManager.Main'
}

tasks.named('test') {
    // Use JUnit Platform for unit tests.
    useJUnitPlatform()
}
m
Please check your settings.gradle file you should have versionCatalog declared in it. Something like this: https://docs.gradle.org/current/userguide/platforms.html#sub:version-catalog-declaration
v
Not necessarily. Typically he would just have the conventional file
gradle/libs.versions.toml
but that is most probably missing.
👍 1
Besides that, I strongly recommend switching to Kotlin DSL. By now it is the default DSL, you immedieately get type-safe build scripts, actually helpful error messages if you mess up the syntax, and amazingly better IDE support if you use a good IDE like IntelliJ IDEA or Android Studio.
👍 1