1616import org .gradle .api .Project ;
1717import org .gradle .api .file .ProjectLayout ;
1818import org .gradle .api .logging .Logger ;
19+ import org .gradle .api .plugins .JavaPluginExtension ;
1920import org .gradle .api .provider .SetProperty ;
2021import org .sonarsource .sonarlint .core .StandaloneSonarLintEngineImpl ;
2122import org .sonarsource .sonarlint .core .analysis .api .AnalysisResults ;
3233import se .solrike .sonarlint .Sonarlint ;
3334import se .solrike .sonarlint .impl .util .NodePluginUtil ;
3435
36+ import javax .annotation .Nullable ;
37+
3538/**
3639 * @author Lucas Persson
3740 */
3841public class SonarlintAction {
3942
4043 private Path mNodeExec ;
4144 private String mNodeVersion ;
45+ @ Nullable
46+ private final JavaPluginExtension mJavaExtension ;
4247
4348 public SonarlintAction (Sonarlint task ) {
4449 Project project = task .getProject ();
50+ mJavaExtension = project .getExtensions ().findByType (JavaPluginExtension .class );
4551 if (project .getExtensions ().findByName ("node" ) != null ) {
4652 NodePluginUtil nodeUtil = new NodePluginUtil ();
4753 if (nodeUtil .getDownload (project )) {
@@ -68,10 +74,9 @@ public List<IssueEx> run(Sonarlint task, SetProperty<File> plugins, ProjectLayou
6874 protected List <IssueEx > analyze (Sonarlint task , Logger logger , SetProperty <File > plugins , ProjectLayout layout ) {
6975 Map <String , String > sonarProperties = new HashMap <>();
7076
71- Project project = task .getProject ();
7277 // Java sourceCompatibility needs to be read so project is actually configured
73- if (project . getProperties (). containsKey ( "sourceCompatibility" ) ) {
74- String sourceCompatibility = project . getProperties (). get ( "sourceCompatibility" ).toString ();
78+ if (mJavaExtension != null ) {
79+ String sourceCompatibility = mJavaExtension . getSourceCompatibility ( ).toString ();
7580 sonarProperties .put ("sonar.java.source" , sourceCompatibility );
7681 }
7782
0 commit comments