I’m using JaCoCo Gradle plugin in my project.
Just as an example of the question, most of my code is under package com.me.mysoftware.
I’m using code generator that generate classes under build/generated/java/....../com/me/software/MyGeneratedClass.java
I would like that all of the classes under this generated directory will be excluded from JaCoCo report, but not the entire package (what’s under src/main/...)
How is this possible?
add excludes = [ com.me.software.MyGeneratedClass ]
see https://docs.gradle.org/current/userguide/jacoco_plugin.html#default_values_of_the_jacoco_task_extension for more help
Related
I have a maven project and the below step is mentioned right after executing surefire tests(for JUnit) and failsafe (for Integration tests). However, I am not able to exclude the files from generated-sources folder. However, if I use a single exclusionPattern:'/tomcat/', it is excluding tomcat folder from the report
I have tried below option:
**```
post {
always {
junit allowEmptyResults: true, testResults: '**/target/failsafe-reports/*.xml'
step( [ $class: 'JacocoPublisher', exclusionPattern: '**/target/generated-sources/**,**/tomcat/**'] )
}
}
```**
but it is only excluding the tomcat folders and not the generated-sources. Still seeing files from this folder in coverage report.
As a workaround, I am targeting the java packages inside target directory to improve coverage. It's not a very efficient way to do it as I had to add entries for multiple packages inside exclusionPattern. But, it works well for my requirement.
Thanks in advance.
I was trying code coverage using ECLemma eclipse plugin. Able to generate the reports on local system.Is there any way we can generate the reports on sonarqube server by changing the properties file..Here is my properties file that i am trying..
sonar.host.url=http://localhost:9000
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
sonar.jdbc.driverClassName=com.mysql.jdbc.Driver
sonar.projectKey=org.accenture.sonarplugin
sonar.projectName=Code Analysis Plugin
sonar.projectVersion=1.0
sonar.junit.reportsPath=code-analysis-rules/target/surefire-reports/code-analysis-rules
sonar.jacoco.reportPath=code-analysis-rules/target/jacoco/Desktop.exec
sonar.sources=src
sonar.language=java
sonar.sourceEncoding=UTF-8
sonar.profile=Sonar way
sonar.android.lint.report=lint-report.xml
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.login = admin
sonar.password = admin*emphasized text*
There's not a way to import these results simply by updating your properties values. You should, however, take a look at the Generic Coverage plugin. Get your coverage data into this format and you'll be able to import it regardless of its origin.
I have a maven java project in some folder (it has some unit tests), and tests for the same code in another different project (different directory). Both source code and test share the same parent pom. Now I want to generate the code coverage report using JaCoCo.
How to instrument sources? How to run tests on instrumented code? And how to integrate and get the result report?
Say Project ABC contains the code and project XYZ contains the test cases.
Note:
Project ABC and Project XYZ are independent projects
Both ABC and XYZ contains multiple sub projects(Need to integrate everything).
I had a similar problem. I found a solution by changing the path of the jacoco report path:
<sonar.surefire.reportsPath>${project.basedir}/../target/surefire-reports</sonar.surefire.reportsPath>
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
I added these properties and configured the jacoco plugin to append reports and not overwrite them by:
<configuration>
<append>true</append>
</configuration>
This way jacoco write the reports to the base directory of the multi module project. The sonar plugin finds these and analyses them.
I had a problem when building a "reference application" with multiple sub-modules and trying to generate test coverage for the sub-modules and have them push to sonarqube. The issue I was having was that since the sub-modules referenced each other, the resulting jacoco reports were getting overwritten and I'd end up with results for a single module. This may not be the same issue as posted above, but I did solve it by using "append" in gradle, so just want to show how to do that.
In the build.gradle file for each module, I have:
testOptions {
unitTests.returnDefaultValues = true
unitTests.includeAndroidResources = true
unitTests.all {
jacoco {
append = true
includeNoLocationClasses = true
}
systemProperty 'robolectric.enabledSdks', '28'
}
}
s
Me and my team are working on a project with a lot of modules. We are using gradle for the project and everyone is new to gradle. We have a Main parent project i.e, parent build with the details of project dependencies. We want to add the integration_test task configuration to all the modules so that we can call the command gradle integration_test. So is there any way or concept of writing the configuration in the main module and make the child projects import the same configuration.
FYI: I tried it by directly adding it to the main project but got an error saying the classpath for the files which I specified does not exists. Any help or thought would be appreciated. Thanks in advance.
Is there a particular reason to split "integration tests" from the standard test task?
If so, you can run the same script for all subprojects from the main project's build file: https://docs.gradle.org/current/userguide/multi_project_builds.html#sec:subproject_configuration
For instance:
subprojects {
task integrationTest {
// whatever you need
}
}
I am note sure if this is what you talk about in the last paragraph. If so, please attache the error message you get.
It is also possible to "import" some configuration by subprojects, but the above definition is better in most scenarios.
I have a simple use case of building an OSGi bundle using Gradle build tool. The build is successful if there are java files present in the build path, but it fails otherwise.
I am using 'osgi' plugin inside the gradle script and trying to build without any java files. The build always fails with following error:
Could not copy MANIFEST.MF to
I am sure there must be some way to do it in Gradle but not able to fine. Any idea what can be done to resolve this depending on your experience.
I ran into this today as well, and #Peter's fix didn't work for me (I hadn't applied the java plugin in the first place...). However, after hours of Googling I did find this thread, which helped me find the problem.
Basically, it seems that the error occurs (as Peter stated) when no class files are found in the jar - my guess is because the plugin then cannot scan the classes for package names on which to base all the Import and Export information.
My solution was to add the following to the manifest specification:
classesDir = theSourceSet.output.classesDir
classpath = theSourceSet.runtimeClasspath
In my actual build code, I loop over all source sets to create jar tasks for them, so then it looks like this:
sourceSets.each { ss ->
assemble.dependsOn task("jar${ss.name.capitalize()}", type: Jar, dependsOn: ss.getCompileTaskName('Java')) {
from ss.output
into 'classes'
manifest = osgiManifest {
classesDir = ss.output.classesDir
classpath = ss.runtimeClasspath
// Other properties, like name and symbolicName, also set based on
// the name of the source set
}
baseName = ss.name
}
}
Running with --stacktrace indicates that the osgi plugin doesn't deal correctly with the case where both the osgi and the java plugins are applied, but no Java code is present. Removing the java plugin should solve the problem.
I had the same issue also when java code was present.
Adding these two lines to the osgiManifest closure fixed the problem:
classesDir = sourceSets.main.output.classesDir
classpath = sourceSets.main.runtimeClasspath
-- erik