Eclipse refuses to support lombok annotation - java

I'm using
Eclipse Version: 2021-09 (4.21.0) Build id: 20210910-1417
Lombok: 1.18.12
But Eclipse complains in the "Problems" tab:
"The method getTest() is undefined for the type RootResponse"
The problem class is:
#Getter
#Builder
#ToString
public class RootResponse extends Serializer {
private String test;
// for use in the cleanup routine
#Override
public String[] getDeletionIdentifiers() {
throw new UnsupportedOperationException("Deletion not supported: "+ this.getClass().getName());
}
}
I'm using Gradle, but am far from an expert at it. Nonetheless, I think this is relevant from the build.gradle file:
ext {
groupId = project.property('groupId')
version = project.property('version')
lombok_version='1.18.12'
functional_api_test_version='1.0-SNAPSHOT'
redwoodCommonVersion='3.5-SNAPSHOT'
}
dependencies {
compile group: 'com.tii', name: 'redwood-common', version: "${redwoodCommonVersion}"
implementation "org.projectlombok:lombok:${lombok_version}"
annotationProcessor "org.projectlombok:lombok:${lombok_version}"
testAnnotationProcessor "org.projectlombok:lombok:${lombok_version}"
implementation 'com.tii:java-functional-testlib:0.5-SNAPSHOT'
implementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.4.0-b180830.0359'
testCompile 'junit:junit:4.12'
}
I also tried adding an external library to Eclipse:
If I click on the #Getter annotation in Eclipse, it finds and opens the lombok.Getter annotation.
I'd like to fix this in Eclipse in a way that I don't need to check in and modify the source. How can I force Eclipse to do this?
Thx, Woodsman

Related

How to exclude dependencies from Gradle Version Catalog?

I'd like to perform the equivalent to the following declaration:
dependencies {
implementation('commons-beanutils:commons-beanutils:1.9.4') {
exclude group: 'commons-collections', module: 'commons-collections'
}
}
But within the version catalog feature. Something like:
dependencyResolutionManagement {
versionCatalogs {
libs {
library('commons-lang3', 'org.apache.commons', 'commons-lang3').exclude {
// group, module etc
}
}
}
}
From a comment on a somewhat unrelated issue:
https://github.com/gradle/gradle/issues/19517#issuecomment-1012159205
(...) the catalog is purely a list of dependencies to pick from.
So, anything else such as exclusions, you must define them as usual in the dependencies { } block.
There's a simple way to do this, which unfortunately isn't documented:
implementation dependencies.create(libs.commons.beanutils.get()) {
exclude group: 'commons-collections', module: 'commons-collections'
}
Note the get() call - beanutils in this case is an instance of Provider<?> so you need to manually unwrap it.
this is pretty ugly but works 👀
in kotlin for example:
vorbisspi = "com.googlecode.soundlibs:vorbisspi:1.0.3.3"
implementation(libs.mp3spi.get().let { "${it.module}:${it.versionConstraint.requiredVersion}" }) {
exclude("javazoom.spi", "spi")
exclude("junit", "junit")
}

Lombok causing MapStruct compileJava build failure after upgrading to Gradle 5.0

We are trying to upgrade from Gradle 4.5 to 5.0. After upgrade, compileJava is failing because Mapstruct is not able to resolve values (getters not available obviously) used in #Mapping annotation. This was working fine in Gradle 4.5 .
The code is like this
#Mapper(componentModel = "spring")
public interface CAndACodeGenConverter extends BaseConverter<CGen, AGen> {
#Mapping(target = "owner", source = "owner.name")
#Mapping(target = "useCA", source = "defaultCA")
AGen convertToDto(CGen entity);
}
Our build.gradle is like this
mapstructVersion = "1.4.1.Final"
lombokVersion = "1.18.12"
lombokMapstructBindingVersion = "0.2.0"
compileOnly('org.projectlombok:lombok:1.18.12')
compile("org.mapstruct:mapstruct:${mapstructVersion}")
implementation "org.mapstruct:mapstruct:${mapstructVersion}", "org.projectlombok:lombok:${lombokVersion}"
annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}", "org.projectlombok:lombok-mapstruct-binding:${lombokMapstructBindingVersion}"
The error we are getting is
error: No property named "owner.name" exists in source parameter(s). Did you mean "null"?
This was working fine in Gradle 4.5 .
Try to change dependencies order like below:
compileOnly "org.projectlombok:lombok:$lombokVersion"
compileOnly "org.mapstruct:mapstruct:${mapstructVersion}"
annotationProcessor "org.projectlombok:lombok-mapstruct-binding:0.2.0"
annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"
annotationProcessor "org.projectlombok:lombok:$lombokVersion"
I've tested it just now and it works.
P.S. IDK why this order is required, got it from lombok-mapstruct-binding related article long time ago

Issue with importing a Gradle project for XNAT - unresolved type

I trying to import a Gradle project for XNAT for the first time using Eclipse 2018-12. I created the project, right clicked, chose Gradle then Existing Gradle Project. After the import completed there is an error with SimpleUploadPlugin.java - "The type org.apache.ecs.ConcreteElement cannot be resolved. It is indirectly referenced from required .class files". I have checked and I have the commons-lang3-3.8.1.jar.
What do I need to do to resolve this issue please?
My build.gradle dependencies are:
// TODO: This is a pretty minimal set of dependencies, so don't worry if you need to add more.
dependencies {
implementation("org.nrg.xnat:web") {
transitive = false
}
implementation("org.nrg.xnat:xnat-data-models") {
transitive = false
}
implementation("org.nrg.xdat:core") {
transitive = false
}
implementation "org.nrg:prefs"
implementation "org.nrg:framework"
implementation("turbine:turbine") {
transitive = false
}
implementation("org.apache.velocity:velocity") {
transitive = false
}
implementation("stratum:stratum") {
transitive = false
}
implementation "log4j:log4j"
implementation "io.springfox:springfox-swagger2"
compile group: 'ecs', name: 'ecs', version: '1.4.2'
}
Another option is to change the dependency configuration for org.nrg.xnat:web from compile or implementation to compileOnly. This lets you declare fewer dependencies for your plugin because you can allow transitive dependencies. The ECS dependency comes from classes in XNAT itself, so allowing the transitive dependencies means you don't have to declare everything that might be indirectly referenced. I just made this change in the XNAT LDAP authentication plugin and went from this:
implementation("org.nrg.xnat:web") {
transitive = false
}
implementation("org.nrg.xnat:xnat-data-models") {
transitive = false
}
implementation("org.nrg.xdat:core") {
transitive = false
}
implementation("org.nrg:prefs") {
transitive = false
}
implementation("org.nrg:framework") {
transitive = false
}
implementation "org.springframework:spring-web"
implementation "org.springframework.security:spring-security-config"
implementation "org.springframework.security:spring-security-ldap"
implementation "org.apache.commons:commons-lang3"
implementation "org.hibernate.javax.persistence:hibernate-jpa-2.1-api"
implementation "com.google.guava:guava"
implementation "org.slf4j:slf4j-api"
implementation "log4j:log4j"
implementation "org.springframework.security:spring-security-web"
implementation "javax.servlet:javax.servlet-api"
compileOnly "com.google.code.findbugs:jsr305"
compileOnly "org.apache.ivy:ivy:2.4.0"
compileOnly("stratum:stratum") {
transitive = false
}
To this:
compileOnly "org.nrg.xnat:web"
compileOnly "org.springframework.security:spring-security-ldap"
compileOnly "org.slf4j:slf4j-nop"
If you run this:
$ ./gradlew dependencies
You'll see that ecs:ecs:1.4.2 gets pulled in through a number of transitive dependencies.
org.apache.ecs.ConcreteElement is from the Apache Element Construction Set (ECS) and for example contained in ecs-1.4.2.jar.
To resolve the issue add a dependency to your build.gradle file like the following:
// https://mvnrepository.com/artifact/ecs/ecs
compile group: 'ecs', name: 'ecs', version: '1.4.2'

IllegalStateException when using Mockito with IntelliJ's Java

The error message I receive:
java.lang.IllegalStateException: Could not initialize plugin:
interface org.mockito.plugins.MockMaker
The code in question:
List<String> mockList = mock(List.class);
The build.gradle dependency:
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
def mockito_version = 'latest.release'
// For local unit tests on your development machine
testCompile "org.mockito:mockito-core:$mockito_version"
}
I have tried looking at other people with the same issue and I keep getting references to PowerMock. I have no idea what that means, so if this is a duplicate I apologize. It just seems like no other question had a solution that resolved my issue. The library is imported properly, as I do not have any compilation errors. Any help would be greatly appreciated.
i tried to create a new project and test this out. below is how my depdencies in gradle file looks:
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile "org.mockito:mockito-core:2.+"
}
below is my test class:
import org.junit.Assert;
import org.junit.Test;
import java.util.List;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class TestList {
#Test
public void Test(){
List<String> myList = mock(List.class);
when(myList.get(0)).thenReturn("hello world");
Assert.assertEquals("hello world",myList.get(0));
}
}
this works.

Is there a way to specify dependencies for a newly created sourceset in gradle?

In gradle I have created a new sourceSet for service testing like this:
sourceSets{
servicetest{
java.srcDirs = [//path to servicetests]
}
}
This source set depends on TestNG, so I was hoping to pull the dependency down by doing something like:
dependencies{
servicetest(group: 'org.testng', name: 'testng', version: '5.8', classifier: 'jdk15')
}
Unfortunately this returns an error. Is there any way to declare a dependency for a specific sourceSet or am I out of luck?
Recent Gradle versions automatically create and wire configurations 'fooCompile' and 'fooRuntime' for each source set 'foo'.
If you are still using an older version, you can declare your own configuration and add it to the source set's compileClasspath or runtimeClasspath. Something like:
configurations {
serviceTestCompile
}
sourceSets {
serviceTest {
compileClasspath = configurations.serviceTestCompile
}
}
dependencies {
serviceTestCompile "org.testng:testng:5.8"
}
The following works for Gradle 1.4.
apply plugin: 'java'
sourceCompatibility = JavaVersion.VERSION_1_6
sourceSets {
serviceTest {
java {
srcDir 'src/servicetest/java'
}
resources {
srcDir 'src/servicetest/resources'
}
compileClasspath += sourceSets.main.runtimeClasspath
}
}
dependencies {
compile(group: 'org.springframework', name: 'spring', version: '3.0.7')
serviceTestCompile(group: 'org.springframework', name: 'spring-test', version: '3.0.7.RELEASE')
serviceTestCompile(group: 'org.testng', name:'testng', version:'6.8.5')
}
task serviceTest(type: Test) {
description = "Runs TestNG Service Tests"
group = "Verification"
useTestNG()
testClassesDir = sourceSets.serviceTest.output.classesDir
classpath += sourceSets.serviceTest.runtimeClasspath
}

Categories