I am relatively new to Eclipse, I am an IntelliJ guy :) So to practice, I have made a dummy Gradle project in Eclipse, and it is not even recognizing the automatically inserted JUnit dependencies.
The stack I am using is the following:
- Gradle 6.6.1
- Java 13
- Eclipse 2019-09 R (4.13.0) --> updated to 2020-09 (4.17.0) as per the suggestions below.
The things I have already done:
Everything from here and here, namely:
Doing the prerequisites to be able to use Lombok (see the code below) according to this guide.
Installing Buildship Gradle.
Inserting the following scripts in my build.gradle:
apply plugin: "eclipse"
and afterwards running
gradlew cleanEclipse eclipse
Setting automatic project synchronization in Preferences and playing with other options on that tab.
Refreshing dependencies and right-clicking. ... and possibly some other things I can not recall properly.
My actual code is the following (mostly auto-generated):
build.gradle:
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java Library project to get you started.
* For more details take a look at the Java Libraries chapter in the Gradle
* User Manual available at https://docs.gradle.org/6.3/userguide/java_library_plugin.html
*/
plugins {
// Apply the java-library plugin to add support for Java Library
id 'java-library'
id "io.freefair.lombok" version "5.2.1"
}
repositories {
// Use jcenter for resolving dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
dependencies {
compileOnly 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'
// only required if Lombok annotation are present in test code
testCompileOnly 'org.projectlombok:lombok:1.18.12'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:28.2-jre'
implementation 'com.google.code.gson:gson:2.8.6'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
}
Library:
package gradleproject;
public class Library {
public boolean someLibraryMethod() {
return true;
}
}
LibraryTest:
/*
* This Java source file was generated by the Gradle 'init' task.
*/
package gradleproject;
import static org.junit.Assert.*;
import org.junit.Test;
public class LibraryTest {
@Test
public void testSomeLibraryMethod() {
Library classUnderTest = new Library();
assertTrue("someLibraryMethod should return 'true'", classUnderTest.someLibraryMethod());
}
}
Animal:
package gradleproject;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class Animal {
private String name;
private int age;
}
Neither the JUnit, nor the Lombok dependencies are recognized after building. Without the lombok dependency, my code actually compiles, even my test runs, but the test class itself (and the code inside) is still underlined and says that it can't resolve the dependencies.
If I try some other libraries, the build fails.
Could you have any suggestions?
Thanks in advance.
PS: I have updated to the latest version of Eclipse and recreated the project. Lamentably, it did not solve the issue.
Eventually, I could solve the problem. The issue was that Gradle somehow did not download the referred projects in the external dependencies folder from the outside repo.
The things I have done:
Subsequently, during the next build process, Gradle downloaded all the referred jars and everything works properly.
Thanks for your help.