Search code examples
javagradlenetbeanspackageguava

could not resolve com.google.guava from gradle


Curious warning from Netbeans:

nb

although I don't see anything from gradle itself, at least so far:

thufir@dur:~/NetBeansProjects/expectit$ 
thufir@dur:~/NetBeansProjects/expectit$ gradle clean

BUILD SUCCESSFUL in 748ms
1 actionable task: 1 up-to-date
thufir@dur:~/NetBeansProjects/expectit$ 
thufir@dur:~/NetBeansProjects/expectit$ tree
.
├── build.gradle
├── gradle
│   └── wrapper
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── LICENSE
├── README.md
├── settings.gradle
└── src
    ├── main
    │   ├── java
    │   │   └── expectit
    │   │       └── App.java
    │   └── resources
    └── test
        ├── java
        │   └── expectit
        │       └── AppTest.java
        └── resources

11 directories, 10 files
thufir@dur:~/NetBeansProjects/expectit$ 

I only ran git init on an essentially empty directory, so it's more just a curiosity than anything else.

But how would I at least generate this warning from gradle itself (which is presumably what the IDE is doing)?

I made a point of adding guava per the instructions, so that the otherwise cherry build file is:

/*
 * This file was generated by the Gradle 'init' task.
 *
 * This generated file contains a sample Java project to get you started.
 * For more details take a look at the Java Quickstart chapter in the Gradle
 * User Manual available at https://docs.gradle.org/6.3/userguide/tutorial_java_projects.html
 */

plugins {
    // Apply the java plugin to add support for Java
    id 'java'

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

repositories {
    // Use jcenter for resolving dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
    mavenCentral()
}

dependencies {
    // This dependency is used by the application.
    implementation 'com.google.guava:guava:28.2-jre'

    // Use TestNG framework, also requires calling test.useTestNG() below
    testImplementation 'org.testng:testng:7.0.0'
}

application {
    // Define the main class for the application.
    mainClassName = 'expectit.App'
}

test {
    // Use TestNG for unit tests
    useTestNG()
}

I only added maven central as above; still get the same warning from the IDE.

gradle version:

thufir@dur:~/NetBeansProjects/expectit$ 
thufir@dur:~/NetBeansProjects/expectit$ gradle -v

------------------------------------------------------------
Gradle 6.3
------------------------------------------------------------

Build time:   2020-03-24 19:52:07 UTC
Revision:     bacd40b727b0130eeac8855ae3f9fd9a0b207c60

Kotlin:       1.3.70
Groovy:       2.5.10
Ant:          Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM:          11.0.7 (AdoptOpenJDK 11.0.7+10)
OS:           Linux 5.4.0-29-generic amd64

thufir@dur:~/NetBeansProjects/expectit$ 

gradlew version:

thufir@dur:~/NetBeansProjects/expectit$ 
thufir@dur:~/NetBeansProjects/expectit$ ./gradlew --version
Downloading https://services.gradle.org/distributions/gradle-6.3-bin.zip
.........10%..........20%..........30%.........40%..........50%..........60%.........70%..........80%..........90%..........100%

------------------------------------------------------------
Gradle 6.3
------------------------------------------------------------

Build time:   2020-03-24 19:52:07 UTC
Revision:     bacd40b727b0130eeac8855ae3f9fd9a0b207c60

Kotlin:       1.3.70
Groovy:       2.5.10
Ant:          Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM:          11.0.7 (AdoptOpenJDK 11.0.7+10)
OS:           Linux 5.4.0-29-generic amd64

thufir@dur:~/NetBeansProjects/expectit$ 

Solution

  • Assuming your wrapper version is the same as your installed version. The problem stems from Netbeans not supporting Gradle 6 (see gradle plugin for netbeans).

    Best option is simply to switch to Gradle 5 (which is supported). To do so you need to update the wrapper properties from gradle/wrapper/gradle-wrapper.properties. Modify the distributionUrl value, and change the end from gradle-6.x-bin.zip to some other version, like gradle-5.2.1-bin.zip.

    Then run a build again so it would download the wrapper and try NetBeans again.

    From what I can tell you build.gradle should work in version 5 as well, so no need to modify it.