I am using Jacoco v0.8.4 and Sonarcube v2.7.1.
I am using the following configuration for SonarCube.
property "sonar.sources", "src/main/java"
property "sonar.binaries","build/intermediates/javac,app/build/tmp/kotlin-classes"
property "sonar.java.binaries", "build/intermediates/javac,app/build/tmp/kotlin-classes"
property "sonar.tests", "src/test/java" // where the tests are located
property "sonar.java.test.binaries", "build/intermediates/javac,app/build/tmp/kotlin-classes"
property "sonar.jacoco.reportPath", "build/jacoco/testDevDebugUnitTest.exec"
property "sonar.java.coveragePlugin", "jacoco"
property "sonar.android.lint.report", "build/reports/lint results.xml"
The SonarCube analysis failed with reason as Invalid value for sonar.java.binaries
> No files nor directories matching 'app/build/tmp/kotlin-classes'
But 'app/build/tmp/kotlin-classes' exist in my project folder.
But, If I remove kotlin things from the property then it provides the coverage for Java files successfully.
Am I doing anything wrong for Kotlin coverage?
you also need to add you build variant folder in pathlike below
property "sonar.java.test.binaries", "build/intermediates/classes/test/, app/build/tmp/kotlin-classes/<BuildVariant>UnitTest"
property "sonar.java.binaries", "build/intermediates/classes/<BuildVariant>/, app/build/tmp/kotlin-classes/<BuildVariant>/"
property "sonar.binaries", "build/intermediates/classes/<BuildVariant>/, app/build/tmp/kotlin-classes/<BuildVariant>/"
and one more thing try to avoid using file name with whitespace like lint results.xml
Related
I want load an external property file and set it values to another properties file, that is possible? e.g:
C:\properties\file.properties
id=userID
password=pass
./main/resources/application.properties
user.id=${id}
user.password=${password}
I tray run this command, but it isn't working
java -jar -Dspring.config.location=C:/properties/file.properties java-1.0-SNAPSHOT.jar
exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'id' in value "${id}"
You can use #PropertySource annotation from spring boot libraries.
Documentation and examples:
https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/annotation/PropertySource.html
I am trying to acces a value defined in application.properties in a following way:
#Value("${server.url}")
private String serverUrl;
It works on embedded tomcat, but when I upload it to Weblogic I get the following error:
Error creating bean with name 'authorizationServiceImpl': Injection of
autowired dependencies failed; nested exception is
java.lang.IllegalArgumentException: Could not resolve placeholder
'server.url' in value "${server.url}"; nested exception is
java.lang.IllegalArgumentException: Could not resolve placeholder
'server.url' in value "${server.url}"
How can I make use of the application.properties file when hosting app on Weblogic server?
I found that if you want to use external properties on weblogic 10.3.6 you need to put the file in desired location and use the follwing annotation for setting property source in configuration/startup class:
#PropertySource(value = { "file:/...domains/MYdomain/application.properties" })
You should never place the application-XXX.properties files specific to an environment in the deployed component itself.
You should always externalize them outside it.
So, to solve your missing properties file problem, you have just to add the properties file(s) in a folder that you will add in the weblogic runtime classpath.
You can set the setDomainEnv.cmd/sh file of your domain and
add the folder path in the CLASSPATH variable.
For example, in Weblogic (11, 12 and maybe other older versions but not sure), in setDomainEnv.cmd, you should find this lines :
set JAVA_OPTIONS=%JAVA_OPTIONS%
#REM SET THE CLASSPATH
Replace #REM SET THE CLASSPATH by
SET CLASSPATH = %CLASSPATH%;yourPropertiesFilesAbsolutePath
I am including security definitions in pom.xml file. When I run a goal mvn compile, it throws an exception:
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.github.kongchen:swagger-maven-plugin:3.1.2:generate (default) on project test: com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input
I have included security definitions in Swagger Maven plugin as below
<securityDefinitions>
<securityDefinition>
<json>src/main/resources/securityDefinition.json</json>
</securityDefinition>
</securityDefinitions>
I have tried with ${basedir} but still get the above exception. How can this be resolved also as the spec says?
The file will be read by getClass().getResourceAsStream, so please note the path you configured. How can I fullfil this condition?
You need to wait to next plugin release (3.1.6). They just merged the changes to the master branch with the solution to the classpath file loading problem that you are facing. The classloader used when the plugin executes has no access to the project's files, be it resources or Java source files.
Next release will have a <jsonPath> tag to allow access to file location and <json> tag for classpath file loading (solving the problem).
Update (tested):
If you don't mind about it you can use the 3.1.6-SNAPSHOT version.
Then, in your POM:
<securityDefinitions>
<securityDefinition>
<jsonPath>${project.basedir}/securityDefinition.json</jsonPath>
</securityDefinition>
</securityDefinitions>
And in the JSON file follow the author's intructions:
https://github.com/kongchen/swagger-maven-plugin
I need to analyse code via Sonar using Gradle and I have some strange problem which I cannot handle. I have the following project structure
-java
|-src
|-main
|-test
|-integration-test
And Sonar analyse only test directory by default and integration-test directory if I change sonar.test property to /src/integration-test, but I want to analyze this two directories together and I actually dont know how to do it. Below we have my sonarqube task properties from gradle.build file.
sonarqube {
properties {
property "sonar.projectName", "projectName"
property "sonar.projectKey", "org.sonarqube:projectName"
property "sonar.host.url", "http://sonar.doesntmetter"
property "sonar.java.coveragePlugin", "jacoco"
property "sonar.junit.reportsPath", "build/test-results/test"
property "sonar.jacoco.reportPath", "build/jacoco/test.exec"
property "sonar.jacoco.itReportPath", "build/jacoco/integrationTest.exec"
property "sonar.login", "admin"
property "sonar.password", "admin"
}
}
What I noticed is that when I run gradle build there would be integrationTest.exec and test.exec in /build/jacoco/ directory, but in case I run gradle sonarqube with default sonar.test property there would be only test.exec, and from other hand when I run gradle sonarqube with sonar.test=/src/integration-test there would be both test.exec and integrationTest.exec.
Dont you know how to analyze unit and integration test in one run?
I think you can add this to your Gradle:
sonarqube {
properties {
properties["sonar.sources"] += sourceSets.custom.allSource.srcDirs
properties["sonar.tests"] += sourceSets.integTest.allSource.srcDirs
}
}
Just use += to add more tests/sources.
More information and examples are here.
EDIT:
Add report paths too! Properties are named:
sonar.surefire.reportsPath - test.testResultsDir (if the directory exists)
sonar.junit.reportsPath - test.testResultsDir (if the directory exists)
EDIT:
I rewrite your code and set sources for testing in one line, check it with your structure
sonarqube {
properties {
property "sonar.projectName", "projectName"
property "sonar.projectKey", "projectKey"
property "sonar.host.url", "http://itsprettyprivate"
property "sonar.java.coveragePlugin", "jacoco"
// Or add it via += to properties, it is up to you ;)
property "sonar.sources", "src/java,src/test,src/integration-test"
//Tells SonarQube where the unit tests execution reports are
property "sonar.junit.reportsPath", "build/test-results/test"
//Tells SonarQube where the unit tests code coverage report is
property "sonar.jacoco.reportPath", "build/jacoco/test.exec"
//Tells SonarQube where the integration tests code coverage report is
property "sonar.jacoco.itReportPath", "build/jacoco/integrationTest.exec"
property "sonar.login", "admin"
property "sonar.password", "password"
}
}
I'm having trouble while developping a maven plugin to find out how to configure the inheritedByDefault property to be set to false in the generated plugin.xml file.
Be careful, I don"t speak about the inheritedByDefault property of each mojo, but the general inheritedByDefault property at the root of the plugin tag.
Plugin descriptor documentation isn't very loquacious about this subject and I can't find anything on Internet.