How to get the property of sonar-project.properties from the Sonar java custom rules

How to get the property of sonar-project.properties from the Sonar java custom rules.

I have written a class using BatchExtension, but it return null. I am using SONARQUBE 7.0

public class PropertyFinder implements BatchExtension {

private static final Logger LOG = LoggerFactory.getLogger(PropertyFinder.class);

public static Settings settings = null;

/**
 * Contructor
 */
public PropertyFinder() {

}

/**
 * Constructor
 * 
 * @param project
 * @param settings
 */
public PropertyFinder(Project project, Settings settings) {
	this.settings = settings;
	LOG.info("Java Custom Version : " + settings.getString("sonar.java.source"));
}



public static Settings getSettings() {
	//System.out.println("the setting is in getter"+settings);
	return settings;
}

}

Edit: my reply here is totally out-of-context, as pointed out below. I’ve read sonar.properties, when in fact the question is around sonar-project.properties


Hi,

What is the use-case here ? sonar.properties is entirely dedicated to system properties for operating the SonarQube server. Any other runtime/functional property should be managed via the SonarQube interface (the beauty of that being that the property value is then tracked/maintained in the backend).

@NicoB Don’t mix sonar-project.properties and sonar.properties :wink:

@asishs What is the version of the plugin API you are developing with? Looking at the classes you are using, it looks very outdated.
I suggest you read this thread, because it is exactly the same question:

1 Like

Wow, my bad for that @asishs :open_mouth: My reply is indeed more confusing than helpful . You’re safe with @Julien_HENRY’s guidance.