Coder Social home page Coder Social logo

remal-gradle-plugins / sonarlint Goto Github PK

View Code? Open in Web Editor NEW
17.0 2.0 2.0 942 KB

A plugin that executes SonarLint checks without SonarQube server

License: MIT License

Groovy 0.05% Shell 0.98% Java 98.97%
gradle gradle-plugin plugin sonar sonarlint sonarqube

sonarlint's Introduction

Tested on Java LTS versions from 8 to 21.

Tested on Gradle versions from 7.1 to 8.8.

name.remal.sonarlint plugin

configuration cache: supported from v3.2

This plugin executes SonarLint inspections without connecting to a SonarQube server.

The plugin uses these Sonar plugins:

For every SourceSet a SonarLint task is created by default.

Configuration

sonarLint {
  isGeneratedCodeIgnored = false // `true` by default, set to `false` to validate generated code (code inside `./build/`)

  // see detailed documentation about `nodeJs` later in the document
  nodeJs {
    nodeJsExecutable = project.layout.projectDirectory.file('/usr/bin/node') // set path to Node.js executable
    detectNodeJs = true // `false` by default, set to `true` to enable automatic Node.js detection
    logNodeJsNotFound = false // Hide warning message about not found Node.js
  }

  rules {
    enable(
      'java:S100', // Enable `java:S100` rule (that is disabled by default)
      'java:S101', // Enable `java:S101` rule (that is disabled by default)
    )
    enabled = ['java:S100'] // `enabled` - a mutable collection of enabled rules

    disable(
      'java:S1000', // Disable `java:S1000` rule
      'java:S1001', // Disable `java:S1001` rule
    )
    disabled = ['java:S1000'] // `disabled` - a mutable collection of disabled rules

    rule('java:S100') {
      property('format', '^[a-z][a-zA-Z0-9]*$') // Configure `format` property for `java:S100` rule
      properties = ['format': '^[a-z][a-zA-Z0-9]*$'] // `properties` - a mutable map of rule properties
    }
  }

  languages {
    include('java', 'kotlin') // Enable Java and Kotlin languages only, all other languages become disabled
    exclude('java', 'kotlin') // Disable Java and Kotlin languages, all other languages remain enabled
  }

  sonarProperty('sonar.html.file.suffixes', '.custom-html') // Configure `sonar.html.file.suffixes` Sonar property
  sonarProperties = ['sonar.html.file.suffixes': '.custom-html'] // `sonarProperties` - a mutable map of Sonar properties

  ignoredPaths.add('**/dto/**') // Ignore all files which relative path matches `**/dto/**` glob for all rules
  rules {
    rule('java:S100') {
      ignoredPaths.add('**/dto/**') // Ignore all files which relative path matches `**/dto/**` glob for rule `java:S100`
    }
  }

  testSourceSets = sourceSets.matching { true } // Which source-sets contain test sources. Source-sets created by plugins like `name.remal.test-source-sets` are automatically integrated. Most probably, you don't have to configure anything yourself.

  logging {
    withDescription = false // Hide rule descriptions from console output
    hideWarnings = true // To hide warnings produced by this plugin
  }

  // `sonarLint` extension extends `CodeQualityExtension` (see https://docs.gradle.org/current/javadoc/org/gradle/api/plugins/quality/CodeQualityExtension.html).
  // You can use all fields of `CodeQualityExtension` the same way as for `checkstyle`, for example.
}

For every property value (for both Sonar properties and rule properties) you can use project.provider { ... } to set a lazy value that will be calculated when a SonarLint task is executed. For example:

sonarLint {
  sonarProperty('sonar.html.file.suffixes', project.provider { '.custom-html' })
}

Help tasks

Two additional help tasks are created:

  1. sonarLintProperties - displays Sonar properties that can be configured via sonarLint.sonarProperties.
  2. sonarLintRules - displays all Sonar rules available, their description and their properties.

Node.js detection

SonarLint requires Node.js of the version 18.17.0 or greater to process CSS, HTML, JavaScript, TypeScript, YAML languages.

If Node.js detection is enabled, the plugin tries to find a Node.js executable automatically. The detection algorithm is:

  1. Try to find a Node.js executable on $PATH
  2. Then try to download a Node.js executable from the official website

If Node.js is successfully detected, is will be used.

If Node.js cannot be detected, CSS, HTML, JavaScript, TypeScript, YAML languages will be excluded.

If OS or CPU architecture does not support official Node.js, the detection won't detect any executable.

If there are no files requiring Node.js in the sources, Node.js detection will be skipped.

Migration guide

Version 3.* to 4.*

Gradle 6 support was removed.

Version 2.* to 3.*

Package name was changed from name.remal.gradleplugins.sonarlint to name.remal.gradle_plugins.sonarlint.

sonarlint's People

Contributors

mergify[bot] avatar remal avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

khauser ssh352

sonarlint's Issues

Configure Sonarlint scan exclusions

The SonarLint plugin in IDEA can ignore some files during the scan through 'File Exclusions', and the Sonarqube has a related configuration: 'property("sonar.exclusions",...)' to achieve this.
I tried adding this configuration in sonarProperty but it didn't work. Does this plugin support the setting of exclusions?
image

Whitelist or blacklist certain languages for analysis

Currently, this plugins enables analysis of certain languages by default (https://github.com/remal-gradle-plugins/sonarlint/blob/main/build.gradle#L140-L145).
However, there seems no option to specifically enable or disable analysis for certain languages. Task sonarlintproperties also does not list a relevant property.
In our case we do not need to analyze Javascript files for instance. Is there an option to disable/enable analysis for certain languages, or can such an option be built?

Can't find java:S5785 issue when run sonarlintTest

Hi remal, I find the plugin can't find some junit issues in test code such as java:S5785. But when I set sourceSets to testSourceSets, the java:S5785 can be find again. This makes me confused. Is this a bug? You can get more information from mydemo. Plugin version is 3.1.0, because I need sonar-java-plugin:7.15 ; gradle version is 6.9.

Failed to compile stylesheet error

With version 4.1.1, running ./gradlew sonarlintmain, gives the following error:

Error at xsl:number on line 83 column 86 of checkstyle.xsl:
  XTSE0975: The level attribute and value attribute must not both be present
Error at xsl:number on line 86 column 87 of checkstyle.xsl:
  XTSE0975: The level attribute and value attribute must not both be present
Error at xsl:number on line 89 column 93 of checkstyle.xsl:
  XTSE0975: The level attribute and value attribute must not both be present

This error happens in a multi-project setup, with Java runtime:

java -version
openjdk version "17.0.9" 2023-10-17
OpenJDK Runtime Environment (Red_Hat-17.0.9.0.9-4) (build 17.0.9+9)
OpenJDK 64-Bit Server VM (Red_Hat-17.0.9.0.9-4) (build 17.0.9+9, mixed mode, sharing)

Running ./gradlew sonarlintmain --stacktrace provides:

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:api:sonarlintMain'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:148)
        at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:282)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:146)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:134)
        at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:51)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:74)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:199)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52)
        at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:42)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:331)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:318)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.lambda$execute$0(DefaultTaskExecutionGraph.java:314)
        at org.gradle.internal.operations.CurrentBuildOperationRef.with(CurrentBuildOperationRef.java:80)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:314)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:303)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:463)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:380)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
        at org.gradle.internal.concurrent.AbstractManagedExecutor$1.run(AbstractManagedExecutor.java:47)
Caused by: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing name.remal.gradle_plugins.sonarlint.SonarLintAction
        at org.gradle.workers.internal.DefaultWorkerExecutor$WorkItemExecution.waitForCompletion(DefaultWorkerExecutor.java:283)
        at org.gradle.internal.work.DefaultAsyncWorkTracker.lambda$waitForItemsAndGatherFailures$2(DefaultAsyncWorkTracker.java:130)
        at org.gradle.internal.Factories$1.create(Factories.java:31)
        at org.gradle.internal.work.DefaultWorkerLeaseService.withoutLocks(DefaultWorkerLeaseService.java:336)
        at org.gradle.internal.work.DefaultWorkerLeaseService.withoutLocks(DefaultWorkerLeaseService.java:319)
        at org.gradle.internal.work.DefaultWorkerLeaseService.withoutLock(DefaultWorkerLeaseService.java:324)
        at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForItemsAndGatherFailures(DefaultAsyncWorkTracker.java:126)
        at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForItemsAndGatherFailures(DefaultAsyncWorkTracker.java:92)
        at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForAll(DefaultAsyncWorkTracker.java:78)
        at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForCompletion(DefaultAsyncWorkTracker.java:66)
        at org.gradle.api.internal.tasks.execution.TaskExecution$3.run(TaskExecution.java:256)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:29)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:26)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.run(DefaultBuildOperationRunner.java:47)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:68)
        at org.gradle.api.internal.tasks.execution.TaskExecution.executeAction(TaskExecution.java:233)
        at org.gradle.api.internal.tasks.execution.TaskExecution.executeActions(TaskExecution.java:216)
        at org.gradle.api.internal.tasks.execution.TaskExecution.executeWithPreviousOutputFiles(TaskExecution.java:199)
        at org.gradle.api.internal.tasks.execution.TaskExecution.execute(TaskExecution.java:166)
        at org.gradle.internal.execution.steps.ExecuteStep.executeInternal(ExecuteStep.java:105)
        at org.gradle.internal.execution.steps.ExecuteStep.access$000(ExecuteStep.java:44)
        at org.gradle.internal.execution.steps.ExecuteStep$1.call(ExecuteStep.java:59)
        at org.gradle.internal.execution.steps.ExecuteStep$1.call(ExecuteStep.java:56)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:199)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73)
        at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:56)
        at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:44)
        at org.gradle.internal.execution.steps.RemovePreviousOutputsStep.execute(RemovePreviousOutputsStep.java:67)
        at org.gradle.internal.execution.steps.RemovePreviousOutputsStep.execute(RemovePreviousOutputsStep.java:37)
        at org.gradle.internal.execution.steps.CancelExecutionStep.execute(CancelExecutionStep.java:41)
        at org.gradle.internal.execution.steps.TimeoutStep.executeWithoutTimeout(TimeoutStep.java:74)
        at org.gradle.internal.execution.steps.TimeoutStep.execute(TimeoutStep.java:55)
        at org.gradle.internal.execution.steps.CreateOutputsStep.execute(CreateOutputsStep.java:50)
        at org.gradle.internal.execution.steps.CreateOutputsStep.execute(CreateOutputsStep.java:28)
        at org.gradle.internal.execution.steps.CaptureStateAfterExecutionStep.executeDelegateBroadcastingChanges(CaptureStateAfterExecutionStep.java:100)
        at org.gradle.internal.execution.steps.CaptureStateAfterExecutionStep.execute(CaptureStateAfterExecutionStep.java:72)
        at org.gradle.internal.execution.steps.CaptureStateAfterExecutionStep.execute(CaptureStateAfterExecutionStep.java:50)
        at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:40)
        at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:29)
        at org.gradle.internal.execution.steps.BuildCacheStep.executeWithoutCache(BuildCacheStep.java:179)
        at org.gradle.internal.execution.steps.BuildCacheStep.lambda$execute$1(BuildCacheStep.java:70)
        at org.gradle.internal.Either$Right.fold(Either.java:175)
        at org.gradle.internal.execution.caching.CachingState.fold(CachingState.java:59)
        at org.gradle.internal.execution.steps.BuildCacheStep.execute(BuildCacheStep.java:68)
        at org.gradle.internal.execution.steps.BuildCacheStep.execute(BuildCacheStep.java:46)
        at org.gradle.internal.execution.steps.StoreExecutionStateStep.execute(StoreExecutionStateStep.java:36)
        at org.gradle.internal.execution.steps.StoreExecutionStateStep.execute(StoreExecutionStateStep.java:25)
        at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:36)
        at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:22)
        at org.gradle.internal.execution.steps.SkipUpToDateStep.executeBecause(SkipUpToDateStep.java:91)
        at org.gradle.internal.execution.steps.SkipUpToDateStep.lambda$execute$2(SkipUpToDateStep.java:55)
        at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:55)
        at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:37)
        at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:65)
        at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:36)
        at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:37)
        at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:27)
        at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:76)
        at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:37)
        at org.gradle.internal.execution.steps.ValidateStep.execute(ValidateStep.java:108)
        at org.gradle.internal.execution.steps.ValidateStep.execute(ValidateStep.java:55)
        at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:71)
        at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:45)
        at org.gradle.internal.execution.steps.SkipEmptyWorkStep.executeWithNonEmptySources(SkipEmptyWorkStep.java:177)
        at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:86)
        at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:53)
        at org.gradle.internal.execution.steps.RemoveUntrackedExecutionStateStep.execute(RemoveUntrackedExecutionStateStep.java:32)
        at org.gradle.internal.execution.steps.RemoveUntrackedExecutionStateStep.execute(RemoveUntrackedExecutionStateStep.java:21)
        at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsStartedStep.execute(MarkSnapshottingInputsStartedStep.java:38)
        at org.gradle.internal.execution.steps.LoadPreviousExecutionStateStep.execute(LoadPreviousExecutionStateStep.java:36)
        at org.gradle.internal.execution.steps.LoadPreviousExecutionStateStep.execute(LoadPreviousExecutionStateStep.java:23)
        at org.gradle.internal.execution.steps.CleanupStaleOutputsStep.execute(CleanupStaleOutputsStep.java:75)
        at org.gradle.internal.execution.steps.CleanupStaleOutputsStep.execute(CleanupStaleOutputsStep.java:41)
        at org.gradle.internal.execution.steps.ExecuteWorkBuildOperationFiringStep.lambda$execute$2(ExecuteWorkBuildOperationFiringStep.java:66)
        at org.gradle.internal.execution.steps.ExecuteWorkBuildOperationFiringStep.execute(ExecuteWorkBuildOperationFiringStep.java:66)
        at org.gradle.internal.execution.steps.ExecuteWorkBuildOperationFiringStep.execute(ExecuteWorkBuildOperationFiringStep.java:38)
        at org.gradle.internal.execution.steps.AssignWorkspaceStep.lambda$execute$0(AssignWorkspaceStep.java:32)
        at org.gradle.api.internal.tasks.execution.TaskExecution$4.withWorkspace(TaskExecution.java:293)
        at org.gradle.internal.execution.steps.AssignWorkspaceStep.execute(AssignWorkspaceStep.java:30)
        at org.gradle.internal.execution.steps.AssignWorkspaceStep.execute(AssignWorkspaceStep.java:21)
        at org.gradle.internal.execution.steps.IdentityCacheStep.execute(IdentityCacheStep.java:37)
        at org.gradle.internal.execution.steps.IdentityCacheStep.execute(IdentityCacheStep.java:27)
        at org.gradle.internal.execution.steps.IdentifyStep.execute(IdentifyStep.java:47)
        at org.gradle.internal.execution.steps.IdentifyStep.execute(IdentifyStep.java:34)
        at org.gradle.internal.execution.impl.DefaultExecutionEngine$1.execute(DefaultExecutionEngine.java:64)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:145)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:134)
        at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:51)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:74)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:199)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52)
        at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:42)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:331)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:318)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.lambda$execute$0(DefaultTaskExecutionGraph.java:314)
        at org.gradle.internal.operations.CurrentBuildOperationRef.with(CurrentBuildOperationRef.java:80)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:314)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:303)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:463)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:380)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
        at org.gradle.internal.concurrent.AbstractManagedExecutor$1.run(AbstractManagedExecutor.java:47)
Caused by: javax.xml.transform.TransformerConfigurationException: Failed to compile stylesheet. 3 errors detected.
        at net.sf.saxon.PreparedStylesheet.prepare(PreparedStylesheet.java:176)
        at net.sf.saxon.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:139)
        at net.sf.saxon.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:91)
        at name.remal.gradle_plugins.sonarlint.internal._relocated.name.remal.gradle_plugins.toolkit.issues.CheckstyleHtmlIssuesRenderer.renderIssues(CheckstyleHtmlIssuesRenderer.java:38)
        at name.remal.gradle_plugins.sonarlint.internal._relocated.name.remal.gradle_plugins.toolkit.issues.IssuesRenderer.renderIssuesToPath(IssuesRenderer.java:19)
        at name.remal.gradle_plugins.sonarlint.internal._relocated.name.remal.gradle_plugins.toolkit.issues.IssuesRenderer.renderIssuesToFile(IssuesRenderer.java:26)
        at name.remal.gradle_plugins.sonarlint.SonarLintAction.execute(SonarLintAction.java:57)
        at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:63)
        at org.gradle.workers.internal.AbstractClassLoaderWorker$1.create(AbstractClassLoaderWorker.java:54)
        at org.gradle.workers.internal.AbstractClassLoaderWorker$1.create(AbstractClassLoaderWorker.java:48)
        at org.gradle.internal.classloader.ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:100)
        at org.gradle.workers.internal.AbstractClassLoaderWorker.executeInClassLoader(AbstractClassLoaderWorker.java:48)
        at org.gradle.workers.internal.IsolatedClassloaderWorker.run(IsolatedClassloaderWorker.java:49)
        at org.gradle.workers.internal.IsolatedClassloaderWorker.run(IsolatedClassloaderWorker.java:30)
        at org.gradle.workers.internal.WorkerDaemonServer.run(WorkerDaemonServer.java:96)
        at org.gradle.workers.internal.WorkerDaemonServer.run(WorkerDaemonServer.java:65)
        at org.gradle.process.internal.worker.request.WorkerAction$1.call(WorkerAction.java:138)
        at org.gradle.process.internal.worker.child.WorkerLogEventListener.withWorkerLoggingProtocol(WorkerLogEventListener.java:41)
        at org.gradle.process.internal.worker.request.WorkerAction.lambda$run$0(WorkerAction.java:135)
        at org.gradle.internal.operations.CurrentBuildOperationRef.with(CurrentBuildOperationRef.java:80)
        at org.gradle.process.internal.worker.request.WorkerAction.run(WorkerAction.java:127)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
        at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
        at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
        at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
        at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:414)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
        at org.gradle.internal.concurrent.AbstractManagedExecutor$1.run(AbstractManagedExecutor.java:47)

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Preset is invalid JSON (github>remal-gradle-plugins/plugins-renovate-config:base)

Dependency check finds some vulnerabilities

Using id 'org.owasp.dependencycheck' version '9.0.9' in my build.gradle shows some issues regarding the sonarlint dependencies:

  • sonar-ruby-plugin-1.15.0.4655.jar
  • sonar-scala-plugin-1.15.0.4655.jar

But I guess these things need to be fixed on their side.

Not possible to ignore html files (follow-up issue #319)

Thanks @remal for a super quick response and for offering a solution in relation to issue 319.

I have tried your suggestion to apply sonarLint.languages.exclude('html') both in my work project as well as the demo project but the plugin insists on trying to scan html files using version 3.4.9.

When I applied version 4.0.0, I didn't see the following error in my own machine possibly because I already had node installed and configured.

Failed to parse Node.js version, got 'Couldn't find the Node.js binary. Ensure you have Node.js installed.'
org.sonar.plugins.javascript.nodejs.NodeCommandException: Failed to parse Node.js version, got 'Couldn't find the Node.js binary. Ensure you have Node.js installed.'

But, I started seeing failure jobs in my Jenkins builds due to

Command returned 1: /jenkins/jenkins/workspace/{project-repo}_PR-{build-number}/build/node-20.12.2-linux-x86_64 -v

Updating Jenkins is not feasible for me so the only option I have is to tell the plugin to not scan html files.

Colorized terminal output

It would be clearer to have colored output in the terminal. (Following #238 )

Something similar as ESlint to give you an idea :

image

Extension of type 'JavaToolchainService' does not exist.

Version 1.5.0 works fine; changing to use 2.0.0-rc-1 causes this error:

$ ./gradlew build

FAILURE: Build failed with an exception.

* Where:
Build file '/home/candrews/projects/test-sonarlint/build.gradle' line: 5

* What went wrong:
An exception occurred applying plugin request [id: 'at.zierler.yamlvalidator', version: '1.5.0']
> Failed to apply plugin 'at.zierler.yamlvalidator'.
   > Could not create task ':sonarLintProperties'.
      > Could not create task of type 'SonarLintPropertiesHelp'.
         > Extension of type 'JavaToolchainService' does not exist. Currently registered extension types: [ExtraPropertiesExtension, StandardDependencyManagementExtension, SpringBootExtension, ReportingExtension, SonarLintExtension, ValidationProperties]

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 451ms
[1]

To reproduce this issue:

  1. git clone https://github.com/candrews/test-sonarlint.git
  2. cd test-sonarlint.git
  3. ./gradlew build

You'll see the aforementioned error.

Plugin does not immediately allow reproducible builds

When building a project with this plugin, and the following Gradle config (see https://docs.gradle.org/current/userguide/resolution_strategy_tuning.html#reproducible-resolution):

configurations.configureEach {
    resolutionStrategy {
        failOnNonReproducibleResolution()
    }
}

The following error is produced:

* What went wrong:
Execution failed for task '...:sonarlintMain'.
> Could not resolve all files for configuration '...:sonarlintCoreClasspath'.
   > Could not resolve org.osgi:org.osgi.service.prefs:[1.1.0,1.2.0).
     Required by:
         project ... org.sonarsource.java:sonar-java-plugin:7.21.0.31796 > org.sonarsource.java:java-frontend:7.21.0.31796 > org.sonarsource.java:jdt:7.21.0.31796 > org.eclipse.jdt:org.eclipse.jdt.core:3.33.0 > org.eclipse.platform:org.eclipse.core.runtime:3.26.100 > org.eclipse.platform:org.eclipse.equinox.preferences:3.10.100
      > Could not resolve org.osgi:org.osgi.service.prefs:[1.1.0,1.2.0): Resolution strategy disallows usage of dynamic versions

Above problem can be resolved by adding:

dependencies {
    constraints {
        sonarlintCoreClasspath("org.osgi:org.osgi.service.prefs:1.1.2") {
            because "a range of versions is specified, which would not allow reproducible builds"
        }
    }
}

As an alternative, Gradle recommends to do "dependency locking" (see also https://docs.gradle.org/current/userguide/resolution_strategy_tuning.html#reproducible-resolution). However, I prefer to avoid version ranges all together, and among many configurations I have in my project, this is the only issue I need to resolve.
I would not be too unhappy fixing the version of org.osgi:org.osgi.service.prefs myself, but maybe it would be good to fix the issue in this plugin? Maybe fixing the issue upstream would be even better, but I don't know if we can expect that from the maintainers of the sonar/eclipse packages.

Note that I am including this Gradle plugin in my own Gradle plugin (for which I need reproducible builds).

Not possible to ignore `html` files

Please, see this demo project which I have tried to ignore html files by following the documentation.

However, no matter what I do, I always get the error:

Failed to parse Node.js version, got 'Couldn't find the Node.js binary. Ensure you have Node.js installed.'
org.sonar.plugins.javascript.nodejs.NodeCommandException: Failed to parse Node.js version, got 'Couldn't find the Node.js binary. Ensure you have Node.js installed.'

Configuration for terminal output

Thanks for this great plugin.

I'm having difficulties going through the terminal output though.
That would be nice to have some configuration to :

  • display coloured output
  • hide rules details

isGeneratedCodeIgnored does not interfere

With this build.gradle

id 'name.remal.sonarlint' version '3.0.9'

sonarLint {
    isGeneratedCodeIgnored = true
}

dependencies {
    ...
    implementation 'com.querydsl:querydsl-core'
    implementation 'com.querydsl:querydsl-jpa'

    annotationProcessor("com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jpa")
    annotationProcessor("jakarta.persistence:jakarta.persistence-api")

The generated Classes from querydsl are annotated with javax.annotation.processing.Generated. The flag isGeneratedCodeIgnored=true is now ending in:

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':sonarlintMain'.
> A failure occurred while executing name.remal.gradle_plugins.sonarlint.SonarLintAction
   > File [uri=file:///<our project path>/build/generated/sources/annotationProcessor/java/main/<one of our querydsl file path>] can't be indexed twice.

I would expect that the generated Classes would be ignored by sonarlint.
Can you help here?

Plugin produces non critical error

When running the SonarLint plugin the following error is produced.

> Task :...:sonarlintMain
Errors occurred while build effective model from /home/meijer/.gradle/caches/modules-2/files-2.1/org.eclipse.platform/org.eclipse.equinox.preferences/3.10.100/43fe3c49d5a6a30090b7081015e4a57bd0a6cb98/org.eclipse.equinox.preferences-3.10.100.pom:
        'modelVersion' must be one of [4.0.0] but is '4.0'. in org.eclipse.platform:org.eclipse.equinox.preferences:3.10.100
Errors occurred while build effective model from /home/meijer/.gradle/caches/modules-2/files-2.1/org.eclipse.platform/org.eclipse.core.contenttype/3.8.200/e2fdb068262514474d73f236adaa821d9c861786/org.eclipse.core.contenttype-3.8.200.pom:
        'modelVersion' must be one of [4.0.0] but is '4.0'. in org.eclipse.platform:org.eclipse.core.contenttype:3.8.200

When running ./gradlew dependencies you can see this is a problem in a transitive dependency from SonarLint core. Any ideas about a fix? This probably needs to fixed upstream, but I guess this issue can be used simply for a version bump for SonarLint core.

Error when running sam build with annotation processors

Attached is a minimal example of a project that needs to be built with the SAM CLI:
sonarlint-issue.zip.

When running sam build on this project I am getting the error Path is outside of root path (/.../sonarlint-issue/gradle-annotation-processor-example): /tmp/tmp3u8o020s/47189bc88fe398efc634e1904be0dc32e518f5d6/build/generated/sources/annotationProcessor/java/main/com/tomgregory/CarMapperImpl.java.
Typical about this project that I have included an example annotation processor (from https://github.com/tkgregory/gradle-annotation-processor-example), and then wrapped it in a "hello world example" from the SAM CLI.

Navigating to gradle-annotation-processor-example and running ./gradlew build from there works fine. So I guess this has to do with the fact that SAM moves the code to a tmp directory. Any idea about a fix?

FYI I am using sam cli version 1.73.0.

IllegalStateException: Cannot build Issue, some of required attributes are not set

For generated code, this error happens:

java.lang.IllegalStateException: Cannot build Issue, some of required attributes are not set [sourceFile, message]
	at name.remal.gradle_plugins.sonarlint.internal._relocated.name.remal.gradle_plugins.toolkit.issues.ImmutableIssue$IssueBuilder.build(ImmutableIssue.java:715)
	at name.remal.gradle_plugins.sonarlint.internal._relocated.name.remal.gradle_plugins.toolkit.issues.Issue.newIssue(Issue.java:27)
	at name.remal.gradle_plugins.sonarlint.internal.latest.SonarLintAnalyzerLatest.lambda$analyze$4(SonarLintAnalyzerLatest.java:81)

Malform input or input contains unmappable characters on UTF-8-encoded Non-ASCII characters

* What went wrong:
Execution failed for task ':app-chatncharge:sonarlintMain'.
> A failure occurred while executing name.remal.gradle_plugins.sonarlint.SonarLintAction
   > Malformed input or input contains unmappable characters: /home/christian.hujer/git/nelkinda/chatncharge4/app-chatncharge/src/main/resources/static/assets/profile_pics/rīgas.jpg

Note the filename: rīgas.jpg

Workaround: Only use ASCII in filenames. (Which is annoying, why is SonarLint even interested in a JPEG file in the resources path.)

Note
This might be a bug in the upstream SonarLint instead of the plugin.

Further information:

  • Gradle version: 8.1.1
  • SonarLint Plugin Version: 3.2.2
  • Encoding: UTF-8
  • Java version: 19.0.2.fx-zulu
  • Project: Kotlin Multi-Module
  • Build File Language: Kotlin Script

Write migration guide for 1.5 -> 2.0

Just got send here by @dependabot. We have been running 1.5.0.

It appears that there have been a few breaking changes since then. For example, it is now sonarLint, not sonarlint anymore. And the way rules are configured changed as well.

Looking at the usage-stats at Maven-Central, I am probably not the only one who got asked to migrate to 2.0.0 now. It would be helpful if someone can provide some sort of migration guide for the breaking changes 👍

Also, where is the old source code? Seems this repo only contains the code from 2.0.0 and its RCs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.