Issue
I have a Maven project with the following structure:
- root
- pom.xml
- project1
- project2
- tck (test compatibility kit)
- pom.xml
- src
- main
- java
The folder tck
contains a package to test compatibility with requirements and are reused in the tests of project1 and project2 to show that those projects are compliant.
tck/pom.xml
follows the structure of https://maven.apache.org/plugins/maven-jar-plugin/examples/create-test-jar.html#the-preferred-way
The issue that I have, is that Maven identifies the tck
package as a regular package with sources files. Indeed, when I open the Module Settings on IntelliJ, for the module tck
it detects src/main/java
as a source folder and not as a test folder.
It is an issue as I use SonarLint on my project, and in the tck
folder, they are tests using asserts. Asserts are not recommended in production code and are spotted by SonarLint. I asked a question on https://community.sonarsource.com/t/sonarlint-running-locally-does-not-catch-parent-pom-xml-rule-exclusion/74764/2, and SonarLint, unlike SonarCloud/Qube, picks its configuration from the Maven project and so if Maven identify it as a source folder and not a test folder, it will report false-positive.
I was wondering if there was a way to declare it clearly on the maven side that this package is a test-package, in order to avoid have the Sonarlint misconfiguration I presented. (I tried the suggestion from the Sonarsource community to change the pom.xml so that the configuration is corrected for all contributors to the project)
Best regards,
Solution
Maven doesn't have a concept of a project as a "test project", only test dependencies. You'll need to specifically configure SonarLint to disable that rule for the module.
Answered By - chrylis -cautiouslyoptimistic-
Answer Checked By - Clifford M. (JavaFixing Volunteer)