My setup:
Sonarqube 5.1.1
Sonar-Maven Plugin 2.6 (also tried 2.7 and 3.6)
JDK 1.7.0_51
Example of the error:
16:00:54 [INFO] [23:00:54.219] Sensor JavaSquidSensor
16:00:55 [INFO] [23:00:55.030] Java Main Files AST scan...
16:00:55 [INFO] [23:00:55.030] 1532 source files to be analyzed
16:00:58 [ERROR] [23:00:57.927] Class not found: javax.annotation.Nullable
16:00:58 [ERROR] [23:00:57.928] Class not found: javax.annotation.CheckReturnValue
16:00:58 [ERROR] [23:00:58.114] Class not found: javax.annotation.Nullable
According to this stackoverflow question, javax.annotation should be part of java 1.7 and up. Furthermore, I've tried putting it in the local maven repository but that didnt help.
So where is Sonar trying to find this package? Any help?!?
Update:
I've tried modifying the sonar-maven-plugin to include a dependency on javax.annotation
I've tried putting the dependency in my maven's settings.xml
Upgrading my JDK to 1.8 has not helped.
According to http://docs.oracle.com/javase/7/docs/api/index.html?javax/annotation/package-summary.html the classes you expect are not part of JDK 7.
The classes you're looking for are part of google JSR-305 implementation that was initiated here https://code.google.com/p/jsr-305/source/browse/trunk/ri/src/main/java/javax/annotation/Nullable.java?r=24 and which moved to Findbugs:
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.0</version>
</dependency>
According to https://jcp.org/en/jsr/detail?id=305 the JSR-305 is finished, but is in dormant status and has not been added to a JDK release yet.
Hope it helps.
To avoid adding SonarQube specific dependencies to your project, define a profile like this:
<profile>
<id>sonarqube</id>
<dependencies>
<dependency>
<groupId>org.joda</groupId>
<artifactId>joda-convert</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies>
</profile>
Then run your sonar analysis with a command like
mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.0.1:sonar -Psonarqube,sonarqube-dev
The sonarqube-dev profile is defined in my ~/.m2/settings.xml and it just specifies where my development environment SonarQube installation is
<profile>
<id>sonarqube-dev</id>
<properties>
<!-- no direct db connections in new sonar -->
<sonar.host.url>
http://localhost:9000/
</sonar.host.url>
</properties>
</profile>
What is achieved by all this?
sonarqube analysis specific dependencies don't pollute the project unnecessarily
no sonarqube maven plugin defined in pom.xml. Each developer and Jenkins can use whatever sonar plugin and server installation they wish
This is more an addendum to the latest answer:
I see similar problems and adding the google findbugs dependency to the project dependencies helps. Similar problems occured with joda convert like
[ERROR] [20:44:25.247] Class not found: org.joda.convert.ToString
Hence I also added
`<dependency>
<groupId>org.joda</groupId>
<artifactId>joda-convert</artifactId>
<version>1.8.1</version>
<scope>provided</scope>
</dependency>`
But note, that I set the scope to provided to prevent these new dependencies to be added to a resulting war file.
However, I still wonder why these errors occur since none of the analyzed classes seem to use these annotations?
Related
After adding module-info.java files to my project my checkstyle plugin start failing with:
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check
(default-cli) on project email: Failed during checkstyle
configuration: NoViableAltException occurred during the analysis of
file
/home/xxx/IdeaProjects/blynk-server/server/notifications/email/src/main/java/module-info.java.
unexpected token: module -> [Help 1]
I tried
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$"/>
</module>
However, it failed with:
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check
(default-cli) on project blynk: Failed during checkstyle
configuration: cannot initialize module
BeforeExecutionExclusionFileFilter - Unable to instantiate
'BeforeExecutionExclusionFileFilter' class, it is also not possible to
instantiate it as
com.puppycrawl.tools.checkstyle.checks.annotation.BeforeExecutionExclusionFileFilter
What is the correct way for skipping module-info.java files during checkstyle for maven-checkstyle-plugin?
Not sure why the Checkstyle filter is not working (this reported bug seems very similar to yours and it was fixed in version 7.3.0, so maybe you need to update Checkstyle).
Anyway the Maven excludes element is also supposed to do this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<excludes>**/module-info.java</excludes>
</configuration>
</plugin>
More in the plugin goal documentation.
BeforeExecutionExclusionFileFilter was added in Checkstyle 7.2.
But the maven-checkstyle-plugin version 3.0.0 (which is the latest version as of 2018-04-01) uses Checkstyle 6.18 by default.
"Checkstyle" and "Checkstyle Maven Plugin" are different things and have different release cycles.
You may want to upgrade the Checkstyle version as follows:
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version> <!-- Checkstyle Plugin version -->
<!-- ... Configuration, Executions ... -->
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.8</version> <!-- Checkstyle version -->
</dependency>
</dependencies>
</plugin>
After that, BeforeExecutionExclusionFileFilter as well as other newer Checkstyle features (e.g. new checks) will be recognized.
Though this doesn't possibly qualify as an answer. Yet being too long to fit in comment, just to keep a note of the track that the maven-checkstyle-plugin is in:-
The last release of the was version 2.17 on 15-Oct-2015 which was almost 2 years back.
The current trunk of maven-plugins points to an ongoing work within the plugin in its 3.0.0-SNAPSHOT version which might mean we can soon expect a org.apache.maven.plugins:maven-checkstyle-plugin:3.0.0 sometime in near future and which would understand the module-info.java as a class.
This doesn't align with the Java+9+-+Jigsaw doc that specifies the list of modules and plugins that are being upgraded to support JDK-9.
I'm currently refactoring lots of pom.xml in various projects and git repo.
Sometimes, a pom in a project A will require an artifact defined in a project B in a version defined by a property :
<dependency>
<groupId>com.example</groupId>
<artifactId>artifact-from-b</artifactId>
<version>${version.from.somewhere}</version>
</dependency>
Sometimes, the version property is not obviously defined in the pom itself or its parent pom. It can be hidden in a parent's parent's parent...
I'm currently trying to find a way to resolve easily properties like ${version.from.somewhere} and find where it is defined.
Any idea of any tool that can help me (apart from eclipse, which fails for some tricky properties) ?
Thanks !
There is a related answer here Is there a way to trace origin of a property in maven pom?
That suggest using mvn help:effective-pom -Dverbose=true then you can find comments like com.example.model:2.1.0-SNAPSHOT.
I tried it and it worked for me.
In my case, the property is defined in the pom of com.example.model:2.1.0-SNAPSHOT in line 407
<dependency>
<groupId>com.example</groupId> <!-- com.example.model:2.1.0-SNAPSHOT, line 405 -->
<artifactId>model</artifactId> <!-- com.example.model:2.1.0-SNAPSHOT, line 406 -->
<version>1.0.6</version> <!-- com.example.model:2.1.0-SNAPSHOT, line 407 -->
I recently added this dependency to pom.xml
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>rest-assured</artifactId>
<version>2.4.0</version>
</dependency>
My builds are failing in jenkins with the following error message:
[WARNING] Found duplicate resources in [org.codehaus.groovy:groovy:2.3.7,org.codehaus.groovy:groovy-json:2.3.7,org.codehaus.groovy:groovy-xml:2.3.7] :
[WARNING] META-INF/groovy-release-info.properties
[JENKINS] Archiving disabled
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5:37.485s
[INFO] Finished at: Mon Mar 09 10:10:49 PDT 2015
[INFO] Final Memory: 46M/381M
[INFO] ------------------------------------------------------------------------
[JENKINS] Archiving disabled
Waiting for Jenkins to finish collecting data
[ERROR] Failed to execute goal com.ning.maven.plugins:maven-duplicate-finder-plugin:1.0.4:check (default) on project LightmileTest: Found duplicate classes/resources -> [Help 1]
Background/Details
I had a similar issue and this threw me for a loop for a while and I started to question my maven knowledge and did some digging. If you want to learn more about duplicate finder, you can read the readme on their github: https://github.com/ning/maven-duplicate-finder-plugin
For the project I was on, I determined I could do excludes in the dependencies or add exceptions to the duplicate finder. I saw both in my project and wondered when it was appropriate to do which.
The message from the plugin helps identify where duplication resides. You'll normally see this when you try to add new dependencies. When you see that, there are two options, either exclude things from the dependencies, or create exceptions in your com.ning.maven.plugins:duplicate-finder-maven-plugin configuration.
Summary / Conclusion
Adding an exception, just ignores the problem. So the cleaner way is add the excludes in the dependencies. This way you get exactly what you expect/desire. Furthermore, going down the exception route would just add a ton of extra work that isn't really useful. So the intent of the plugin is to help you identify duplications, then try to handle them via excludes in the dependencies.
Example of How to Do Exclude
In your example/case, one of the following should work for you:
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>rest-assured</artifactId>
<version>2.4.0</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-json</artifactId>
</exclusion>
</exclusions>
</dependency>
or
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>rest-assured</artifactId>
<version>2.4.0</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
</exclusion>
</exclusions>
</dependency>
It is likely that your new dependency is failing on this test your are doing via Maven (duplicate-finder-plugin). Run the manual check from command line (on the level of the POM file) to find out what are the offending classes:
mvn com.ning.maven.plugins:duplicate-finder-maven-plugin:1.0.4:check
Then you can either remove the dependency or configure the Maven plugin to ignore these. (config here)
dependency:analyze-duplicate Analyzes the and tags in the pom.xml and determines the duplicate declared dependencies.
mvn dependency:analyze-duplicate
What you can do is to follow the rule of scope, meaning that, separate dependencies according to their scopes, such as in your case, rest assured used for testing, why not to put it under the scope of a test:
<scope>test</scope>
Secondary, what I usually do is executing exactly same commands from Jenkins on my local machine and usually it does help, from you error log I think it is not rest assured related, so please try to run MVN goal which is on Jenkins side locally and make sure you have the same error. If not, it can be a different configuration of maven for example via settings.xml in Jenkins machine.
Use to avoid the duplicate finder.
I am using the maven-jspc-plugin in my pom.xml.
When i try to execute the jsp-compile goal (which executes the plugin) I get:
Caused by: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.apache.juli.logging.Slf4jLog.<init>(Slf4jLog.java:29)
at org.apache.juli.logging.LogFactory.getLog(LogFactory.java:54)
at org.apache.juli.logging.LogFactory.getLog(LogFactory.java:35)
at org.apache.sling.scripting.jsp.jasper.compiler.OriginalTldLocationsCache.<init>(OriginalTldLocationsCache.java:81)
at org.apache.sling.maven.jspc.JspcMojo.initServletContext(JspcMojo.java:426)
I've tried downloading the (open) source for the maven-jspc-plugin and i am able to easily "mvn install" -- I don't get any build issues, however when i use that build in my project pom it still crashes and tells me it can't find LoggerFactory.
I've logged an issue with the Apache Sling project but am not making much headway.
https://issues.apache.org/jira/browse/SLING-2350
This link includes some more troubleshooting info as well as a simple maven project that uses the maven plugin. downloading the jspc-test.zip and "mvn install"ing will result in the error I've mentioned.
Also, i took a peak at the org.apache.juli pom.xml and it doesnt appear to list any dependencies at all.
Any thoughts on how to resolve would be appreciated.
Thanks!
Plugin dependencies are supplied in a different part of the POM:
<project>
<dependencies>
<!-- dependencies defined here don't get included for plugins -->
...
</dependencies>
<build>
<plugins>
<plugin>
.... jspc plugin section ....
<dependencies>
<dependency>
<!-- Try adding slf4j here --->
Though it does sounds like their POM is invalid if it doesn't already specify slf4j.
I just updated Maven from 2.0.9 to 2.2.1 and I'm getting the following exception when running a maven build:
INFO] [antrun:run {execution: precompile-jsp}]
[INFO] Executing tasks
default:
jspc:
[mkdir] Created dir: C:\builds\trunk\webapps\vyre_portlets\WEB-INF\jsp_src
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] An Ant BuildException has occured: The following error occurred while executing this line:
C:\unify\trunk\portlets\build-jsps.xml:87: The following error occurred while executing this line:
C:\unify\trunk\portlets\build-jsps.xml:7: java.lang.IllegalAccessError: tried to access method org.apache.tools.ant.launch.Locator.decodeUri(Ljava/lang/String;)Ljava/lang/String; from class org.apache.tools.ant.AntClassLoader
The build-jsps.xml ant script runs the org.apache.jasper.JspC task to precompile JSP in the a webapp that maven is building. This was working fine with Maven 2.0.9.
Google gives a bunch of people asking similar questions, but no answers. Has anyone run into this and knows how to resolve this? Or even just why I'm getting the IllegalAccessError?
try to set ANT dependency for "maven-antrun-plugin" explicitly.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
....
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-nodeps</artifactId>
<version>1.7.0</version>
</dependency>
</dependencies>
</plugin>
Note that there are multiple places where you can find ANT in Maven's public repository:
<groupId>org.apache.ant</groupId>
<groupId>ant</groupId>
(2) is the old one so use (1) instead
In Maven 2.2.x, the versions of many of the plugins have been updated, if you run the build with -X, you'll see what version of the antrun-plugin has been used. If these are different versions, it may be using a different version of org.apache.tools.ant.launch.Locator. Looking at the change history for Locator, the decodeUri method was introduced in Ant 1.7 and has been tweaked a few times, though nothing that would obvioulsy cause the problem.
Can you post a minimal pom and ant configuration that shows the error? this would help diagnose the problem.