Must-share information (formatted with Markdown):
- which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
id 'org.sonarqube' version '4.4.1.3373'
SonarLint 10.2.1.77304
- how is SonarQube deployed: zip, Docker, Helm
Docker on my local using this docker-compose.yml
version: '3'
services:
sonarqube:
image: sonarqube
ports:
- "9000:9000"
environment:
- SONARQUBE_JDBC_URL=jdbc:h2:tcp://sonarqube-db:9092/sonar
networks:
- sonarnet
container_name: sonarqube
restart: unless-stopped
networks:
sonarnet:
driver: bridge
- what are you trying to achieve
Iām trying to make Sonar see private
access modifiers, which I add using @FieldDefaults(level = PRIVATE)
lombok annotation on my java class. When I run ./gradlew build clean sonar
it anyway highlights it as maintainability problem in results -
Fields in a āSerializableā class should either be transient or serializable[java:S1948]
To fix this it recommends to āMake āmyFieldNameā private or transient.ā, however in compiled .class file for this java class I see that this field is private.
- what have you tried so far to achieve this
After searching a lot Iāve managed to specify sonar property āsonar.java.librariesā in my build.gradle
file to point to the location of my lombok.jar file in .gradle/caches dir.
Final property looks like this:
property "sonar.java.libraries", System.getenv().get("GRADLE_USER_HOME") + "/caches/**/**/**/lombok/**/**/*.jar"
After this it stopped highlighting some problems. But still for some classes which implement Serializable
interface and have List of another Serializable
object as a field, it highlights same maintainability problem.
Iāve also tried specifying property "sonar.java.binaries"
property to point to by build/classes
folder (which I suppose the value for sonar in gradle by default) and I debugged it with different pathes, even with absolute path, but that didnāt help. However, and interesting fact, is that when I configured my SonarLint IDEA plugin and specified sonar.java.binaries
& sonar.java.libraries
properties in a plugin config it became behaving correctly, it stopped highlighting this maintainability problem. Just in case, after this configuration of plugin it still shows other real problems in code, so that didnāt get broken with new properties.
I spent much time to achieve same result which I achieved for SonarLint plugin but for SonarQube server which I use with ./gradlew but no luck now.
Providing classes samples for wider picture:
@Data
@Builder
@FieldDefaults(level = PRIVATE)
public class Window implements Serializable {
String name;
List<RadioButtonEntry> buttons;
}
and RadioButtonEntry class code:
@Data
@NoArgsConstructor
@AllArgsConstructor
@FieldDefaults(level = PRIVATE)
public class RadioButtonEntry implements Serializable {
String label;
}
and the screenshot of results for this code from Sonar: