Hello everybody,
I just started some playstuff with Kotlin and like it. I am working in build engineering and we use SonarQube a lot.
What would be the recommended way to implement a new plugin for a JVM language which mostly uses Maven or relies on structures similar to Maven, e.g. test results are found at target/surefire-reports etc.
I just installed SQ 6.2 locally and tried some different approaches:
## Reconfigure SQ to handle kotlin like java.
* I started the analysis with `mvn verify sonar:sonar -Dsonar.java.file.suffixes=.kt -Dsonar.login=admin -Dsonar.password=admin`, the project already uses jacoco-0.7.8
* This led to an expectable parse error with the "Java Main Files AST scan".
* Lateron the Surefire and Jacoco sensors could not find any files, which is understandable.
Then I forked I forked the kotlin-sonar[0] plugin which provides only very basic XML-rule support and tried different approaches
to get coverage (and surefire) running, see my fork at [1]:
## Brute-Force copy of the groovy-plugin
* In the master branch I just copied and adapted the code from the groovy-plugin as a POC, coverage was shown and unit tests results were reported.
* One issue I ran into during coverage reporting was a inconsistency concerning line numbers which led to a IllegalStateException in NewCoverage which I catched in the this approach[5]:
** With Kotlin you often get multiple class files (see e.g AKotlinThing.kt[3], where the compiler produces three class files[4])
** The code coverage seems to only take into account the information for the "main" class and seems to be confused later on because the source file reports more lines than the coverage coming via jacoco.exec
## Facading the java-plugin)
* Now this did work somehow, however it seems to be a *huge* invest as a lot of method calls are already deprecated as of today and this is quite untested.
* Because SQ is quite quick in making incompatible API changes, I thought of reusing the officially supported java-plugin which seems to be a lesser effort.
* As outlined in the previous approach, the Jacoco Sensors fail, because the last-line information found in jacoco.exec does not correspond to the lines of the source file.
* SonarQube bails with something like:
at org.sonar.api.internal.google.common.base.Preconditions.checkState(Preconditions.java:173)
at org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage.validateLine(DefaultCoverage.java:89)
at org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage.lineHits(DefaultCoverage.java:77)
at org.sonar.plugins.jacoco.AbstractAnalyzer.analyzeFile(AbstractAnalyzer.java:256)
at org.sonar.plugins.jacoco.AbstractAnalyzer.readExecutionData(AbstractAnalyzer.java:139)
at org.sonar.plugins.jacoco.AbstractAnalyzer.analyse(AbstractAnalyzer.java:102)
at org.sonar.plugins.jacoco.JaCoCoSensor.execute(JaCoCoSensor.java:87)
If you read up until, thanks a lot :-).
Now to reiterate: what would be the recommended way to implement a new plugin for a JVM language which mostly uses Maven?
Thanks for any comments
Mirko