I have a project that has the following package structure
src/main/proj
-com.company.package
-appName
-morepackages
-appVersion2
-morepackages
sonar-runner.properties
sonarBuild.sh
sonar-runner-project2.properties
sonarBuildProject2.sh
As it stands, with the default properties file i can run the sonar report and it will generate a review for the whole project
sonar.projectKey=KEY
sonar.projectName=PROJNAME
sonar.projectVersion=1.0
sonar.host.url=someurl
#Path for sonar sources
sonar.sources=src/main/java
#Path for libraries
sonar.libraries=target/lib/*.jar
#Path for binaries
sonar.binaries=target/classes
#--------Default database
sonar.jdbc.url=someurl
sonar.jdbc.driver=com.mysql.jdbc.Driver
#----- Global database settings
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
#----- Default directory layout
sonar.java.source=1.6
sonar.java.target=1.6
sonar.sourceEncoding=UTF-8
Ideally however I would like to separate the two reports so i have one for the original package and one for the appVersion2 package. Now - as mentioned above I have created a separate properties file for each. Should i just point sonar.sources to the respective packages for each job to analyse or is there a better way to do this all in one property file?
Thanks
EDIT
My multi module attempt properties file looks as follows
sonar.projectKey=rootkey
sonar.projectName=rootname
sonar.projectVersion=1.0
sonar.host.url=rooturl
sonar.sources=src/main/java/
sonar.libraries=target/lib/*.jar
sonar.modules=module1,module2
sonar.sourceEncoding=UTF-8
#----- Global database settings
sonar.jdbc.username=user
sonar.jdbc.password=pass
sonar.java.source=1.7
sonar.java.target=1.7
#--------Default database
sonar.jdbc.url=url
sonar.jdbc.driver=com.mysql.jdbc.Driver
module1.sonar.projectName=proja
module2.sonar.projectName=projb
module1.sonar.projectKey=projakey
module2.sonar.projectKey=projbkey
#Path for sonar sources
module1.sonar.sources=src/main/java/app1code
module2.sonar.sources=src/main/java/app2code
#Path for binaries
module1.sonar.binaries=target/classes/app1binaries
module2.sonar.binaries=target/classes/app2binaries
I get an error in the output saying....
Exception in thread "main" org.sonar.runner.RunnerException: org.sonar.runner.RunnerException: The base directory of the module 'module1' does not exist: patthtoapp/module1
at org.sonar.runner.Runner.delegateExecution(Runner.java:288)
at org.sonar.runner.Runner.execute(Runner.java:151)
at org.sonar.runner.Main.execute(Main.java:84)
at org.sonar.runner.Main.main(Main.java:56)
Caused by: org.sonar.runner.RunnerException: The base directory of the module 'module1' does not exist: pathtoapp/module1
at org.sonar.runner.internal.batch.SonarProjectBuilder.setProjectBaseDir(SonarProjectBuilder.java:279)
at org.sonar.runner.internal.batch.SonarProjectBuilder.loadChildProject(SonarProjectBuilder.java:191)
at org.sonar.runner.internal.batch.SonarProjectBuilder.defineChildren(SonarProjectBuilder.java:169)
at org.sonar.runner.internal.batch.SonarProjectBuilder.generateProjectDefinition(SonarProjectBuilder.java:122)
at org.sonar.runner.internal.batch.Launcher.execute(Launcher.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.sonar.runner.Runner.delegateExecution(Runner.java:285)
You have to specify the projectBaseDir if the module name doesn't match you module directory.
Since both your module are located in ".", you can simply add the following to your sonar-project properties:
module1.sonar.projectBaseDir=.
module2.sonar.projectBaseDir=.
Sonar will handle your modules as components of the project:
EDIT
If both of your modules are located in the same source directory, define the same source folder for both and exclude the unwanted packages with sonar.exclusions:
module1.sonar.sources=src/main/java
module1.sonar.exclusions=app2code/**/*
module2.sonar.sources=src/main/java
module2.sonar.exclusions=app1code/**/*
More details about file exclusion
You can define a Multi-module project structure, then you can set the configuration for sonar in one properties file in the root folder of your project, (Way #1)
Do the build job on Jenkins first without Sonar configured. Then add Sonar, and run a build job again. Should fix the problem
Related
For running JTable in Java Swing at Eclips 2020-06, imported rs2xml.jar file. But after that, while running the program, the following error is occurring.
Error occurred during initialization of boot layer
java.lang.module.FindException: Unable to derive module descriptor for E:\Progrm Learning\JAVA\Student\rs2xml.jar
Caused by: java.lang.module.InvalidModuleDescriptorException: JDOMAbout$Author.class found in top-level directory (unnamed package not allowed in module)
rs2xml.jar contains a class in the default package which is not allowed when using JPMS.
In Project > Properties: Java Build Path, tab Libraries move rs2xml.jar from the Modulepath to the Classpath and in the project, in the source folder, in the default package delete your module-info.java file to not use JPMS.
The answer provided by #howlger works but if after deleting your module-info.java file your
src file gives error then you could start a new project and while creating new project select don't create module-info
Nice question.
rs2xml.jar contains a class in the default package which is not allowed when using JPMS.
In Project > Properties: Java Build Path > Libraries, move rs2xml.jar from the Modulepath to the Classpath.
Then in the project, in the source folder, and in the default package delete your module-info.java file in order to not use JPMS.
I'm working on a Spring multi-module project. One of the child modules has some files under /test/resources/certs/ and a property file under /test/resources/test-ssl.properties.
───resources
│ test-ssl.properties
├───certs
│ test-keystore.p12
test-ssl.properties has a property that points to /certs/test-keystore.p12file.
server.ssl.trust-store=/certs/test-keystore.p12
In child modules pom.xml I'm using Maven plugin test-jar and in parent pom I've added this module as a dependency.
With this structure integration test present in parent module is able to successfully read classpath:test-ssl.properties but it fails to resolve its property value.
Spring throws FileNotFoundException: \certs\test-keystore.p12. What change we can do to make Spring read a file present in test jar?
Also tried the following patterns,
server.ssl.trust-store=classpath:/certs/test-keystore.p12
server.ssl.trust-store=classpath:certs/test-keystore.p12
server.ssl.trust-store=classpath*:/certs/test-keystore.p12
Please note that this test property doesn't try to load any certificate. It is there because property placeholder can find some value for the property during build.
Issue is resolved by changing integration-test phase to process-test-resources.
Credit goes to the following answer of Pascal Thivent:
The content of the test output directory (target/test-classes) is on the class path, not src/test/resources. But resources under src/test/resources are copied to the test output directory by the resources:testResources goal (which is bound by default to the process-test-resources phase).
I am using Akka actors for Remote communication in karaf.
When I deploy the jar file generated after compiling using maven, I get the following error:
Exception in thread "Thread-113"
com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'akka.version'
at com.typesafe.config.impl.SimpleConfig.findKeyOrNull(SimpleConfig.java:152)
at com.typesafe.config.impl.SimpleConfig.findOrNull(SimpleConfig.java:170)
at com.typesafe.config.impl.SimpleConfig.findOrNull(SimpleConfig.java:176)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:184)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:189)
at com.typesafe.config.impl.SimpleConfig.getString(SimpleConfig.java:246)
at akka.actor.ActorSystem$Settings.(ActorSystem.scala:168)
at akka.actor.ActorSystemImpl.(ActorSystem.scala:522)
at akka.actor.ActorSystem$.apply(ActorSystem.scala:142)
at akka.actor.ActorSystem$.apply(ActorSystem.scala:119)
at org.opendaylight.com.test.rem$$anon$1.run(rem.scala:19)
I even added Maven shade plugin in the pom file which was suggested in other answers, but adding the plugin makes all the karaf features to change to ''Resolved'' state. The configuration file for akka is in the classpath too. As of my knowledge, the akka configuration file is not being read at all, as I got the same exception even after removing the configuration file.
This error is most often caused by combining multiple Akka jars into a single super-jar and not handling the reference.conf files correctly. The reference.conf file in each of the Akka module jar-files needs to be concatenated into a single file in the super jar.
Follow the instructions in the docs here: https://doc.akka.io/docs/akka/current/scala/general/configuration.html#when-using-jarjar-onejar-assembly-or-any-jar-bundler
And then verify that the jar-file you use when running has the contents of all those reference.conf files concatenated into a single file.
After deploy custom rule (like https://github.com/SonarSource/sonar-java/blob/master/java-checks/src/main/java/org/sonar/java/checks/UselessImportCheck.java), when I start SonarQube 4.2, following exception is thrown during sonar start:
Caused by: java.lang.ClassNotFoundException: com.sonar.sslr.api.AstAndTokenVisitor
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50) ~[plexus-classworlds-2.2.3.jar:na]
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244) ~[plexus-classworlds-2.2.3.jar:na]
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230) ~[plexus-classworlds-2.2.3.jar:na]
... 44 common frames omitted
Above mentioned class should be found in sslr-core-1.19.2.jar, which I found in location sonarqube-4.2/web/deploy/plugins/squidjava/META-INF/lib/sslr-core-1.19.2.jar
Am I missing some step to enhnance default sonar libraries?
Currently installed plugins are(sonarqube-4.2/extensions/plugins):
sonarqube-4.2/extensions/plugins/sonar-checkstyle-plugin-2.1.jar
sonarqube-4.2/extensions/plugins/sonar-web-plugin-2.1.jar
sonarqube-4.2/extensions/plugins/sonar-jacoco-plugin-2.2.1.jar
sonarqube-4.2/extensions/plugins/sonar-java-plugin-2.2.1.jar
sonarqube-4.2/extensions/plugins/sonar-surefire-plugin-2.2.1.jar
sonarqube-4.2/extensions/plugins/sonar-pmd-plugin-2.2.jar
sonarqube-4.2/extensions/plugins/sonar-findbugs-plugin-2.2.1.jar
sonarqube-4.2/extensions/plugins/sonar-squid-java-plugin-2.2.1.jar
What should I do to prevent above mentioned exception(except undeploy mentioned custom plugin)?
Should be necessary libraries bundled directly in to the custom plugin? I expected sonar to have such libraries bundled.
Finally I found solution/explanation for the problem:
sonarqube-4.2/web/deploy/plugins/ directory is dynamically updated during sonar start from the sonarqube-4.2/extensions/plugins directory. Every plugin should have lib directory in his META-INF jar.Such lib directory should contain all necessary libraries.
In my case:
META-INF/lib/asm-5.0.1.jar
META-INF/lib/java-checks-2.2.1.jar
META-INF/lib/java-squid-2.2.1.jar
META-INF/lib/jaxen-1.1.4.jar
META-INF/lib/sslr-core-1.19.2.jar
META-INF/lib/sslr-squid-bridge-2.3.jar
META-INF/lib/sslr-xpath-1.19.2.jar
And META-INF/MANIFEST.MF must besides othet important definitions contain link to these libraries:
Plugin-Dependencies: META-INF/lib/java-checks-2.2.1.jar META-INF/lib/j
axen-1.1.4.jar META-INF/lib/sslr-squid-bridge-2.3.jar META-INF/lib/ss
lr-xpath-1.19.2.jar META-INF/lib/asm-5.0.1.jar META-INF/lib/sslr-core
-1.19.2.jar META-INF/lib/java-squid-2.2.1.jar
After these steps deploy success and plugin is ready to be used.
Above mentioned fact is may be clear for MAVEN users (there is lot of pom files),but gradle users must create such builds on their own and this information may be useful for them.
Good luck!
I am trying to setup Hibernate tools – attaching it to the spring petclinic project. So far the problem is in classpath. My actions:
Click on hibernate on the Hibernate Configuration view
Add
postgresql-9.1.jar located in the root directory of the
spring-petclinic project
The result is the error: [Classpath]: Archive classpath entry doesn't exist [/spring-petclinic/postgresql-9.1.jar] ( see http://jboston.net/HIbernateToolsError.jpg for the image)
See also the log:
java.lang.IllegalArgumentException: Path must include project and resource name: /postgresql-9.1.jar
java.lang.IllegalArgumentException: Path must include project and resource name: /postgresql-9.1.jar
at org.eclipse.core.runtime.Assert.isLegal(Assert.java:63)
at org.eclipse.core.internal.resources.Workspace.newResource(Workspace.java:2170)
at org.eclipse.core.internal.resources.Container.getFile(Container.java:208)
at org.hibernate.eclipse.console.utils.ProjectUtils.findJavaProjects(ProjectUtils.java:308)
at org.hibernate.eclipse.console.workbench.ProjectCompilerVersionChecker.validateProjectComplianceLevel(ProjectCompilerVersionChecker.java:35)
at org.hibernate.eclipse.console.workbench.ConsoleConfigurationWorkbenchAdapter.getChildren(ConsoleConfigurationWorkbenchAdapter.java:37)
at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.getChildren(BasicWorkbenchAdapter.java:100)
at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.fetchDeferredChildren(BasicWorkbenchAdapter.java:106)
at org.eclipse.ui.progress.DeferredTreeContentManager$1.run(DeferredTreeContentManager.java:235)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
#Craig Ringer answer helped. My workaround was as follows:
Create the user library with a postgresql jdbc jar
From the Hibernate configuration classpath tab select Advanced on the
right menu
Choose "Add library"
It looks like you've attempted to add the JDBC jar as a required project. Don't. Add it as a library dependency instead.
See this list of ways to do it - unverified, as I thankfully no longer have to use Eclipse anymore.