Skip to content

Commit

Permalink
Change of cobertura plugin for jacoco plugin (#59)
Browse files Browse the repository at this point in the history
-  Replace cobertura with jacoco

- Update pipeline with jacocoMergedReport gradle task

- Update plugin version

- Fix report destination
  • Loading branch information
juancgalvis authored Jun 4, 2020
1 parent ca1d1da commit 317055e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 49 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ To use the plugin you need Gradle version 5 or later, to start add the following

```groovy
plugins {
id "co.com.bancolombia.cleanArchitecture" version "1.5.4"
id "co.com.bancolombia.cleanArchitecture" version "1.5.5"
}
```

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
package=co.com.bancolombia
systemProp.version=1.5.4
systemProp.version=1.5.5
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class PluginTemplate {
public static final String GENERATING_CHILDS_DIRS = "Generating Childs Dirs";
public static final String GENERATED_CHILDS_DIRS = "Childs Dirs Generated";
public static final String WRITED_IN_FILES = "Files Generated ";
public static final String VERSION_PLUGIN = "1.5.4";
public static final String VERSION_PLUGIN = "1.5.5";

private PluginTemplate() {
}
Expand Down
80 changes: 36 additions & 44 deletions src/main/java/co/com/bancolombia/templates/ScaffoldTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ScaffoldTemplate {
public static final String READ_ME = "Readme.md";
public static final String IMPERATIVE_PROJECT = "imperative";
public static final String SONAR_PLUGIN_VERSION = "2.7";
public static final String NET_SALIMAN_COBERTURA_VERSION = "3.0.0";
public static final String JACOCO_TOOL_VERSION = "0.8.5";

public static final String LOMBOK_CONFIG_CONTENT = "lombok.addLombokGeneratedAnnotation = true";

Expand Down Expand Up @@ -396,7 +396,6 @@ private ScaffoldTemplate() {

public static String getMainGradleContent(String type) {
String value = "allprojects {\n" +
" apply plugin: 'net.saliman.cobertura'\n" +
" repositories {\n" +
" mavenCentral()\n" +
" maven { url \"https://repo.spring.io/snapshot\" }\n" +
Expand All @@ -405,18 +404,12 @@ public static String getMainGradleContent(String type) {
"}\n" +
"\n" +
"subprojects {\n" +
" apply plugin: \"java\"\n" +
" apply plugin: 'net.saliman.cobertura' \n" +
" apply plugin: 'java'\n" +
" apply plugin: 'jacoco' \n" +
" apply plugin: 'io.spring.dependency-management'\n" +
"\n" +
" sourceCompatibility = JavaVersion.VERSION_1_8\n" +
"\n" +
" repositories {\n" +
" \t\t mavenCentral()\n" +
" maven { url \"https://repo.spring.io/snapshot\" }\n" +
" maven { url \"https://repo.spring.io/milestone\" }\n" +
" }\n" +
"\n" +
" dependencies {\n" +
" testImplementation 'org.springframework.boot:spring-boot-starter-test'\n";
if (!type.equals(IMPERATIVE_PROJECT)) {
Expand All @@ -431,12 +424,17 @@ public static String getMainGradleContent(String type) {
" testCompileOnly 'org.projectlombok:lombok'\n" +
" }\n" +
"\n" +
" test.finalizedBy(project.tasks.jacocoTestReport)" +
"\n" +
" cobertura {\n" +
" coverageFormats = [ 'xml', 'html' ]\n" +
" }\n" +
"\n" +
" test.finalizedBy(project.tasks.cobertura)" +
" jacocoTestReport {\n" +
" dependsOn test\n" +
" reports {\n" +
" xml.enabled true\n" +
" xml.destination file(\"${buildDir}/reports/jacoco.xml\")\n" +
" csv.enabled false\n" +
" html.destination file(\"${buildDir}/reports/jacocoHtml\")\n" +
" }\n" +
" }"+
"\n" +
" dependencyManagement {\n" +
" imports {\n" +
Expand All @@ -446,19 +444,23 @@ public static String getMainGradleContent(String type) {
" }\n" +
"}\n" +
"\n" +
"def files = subprojects.collect { new File(it.projectDir, '/build/cobertura/cobertura.ser') }\n" +
"\n" +
"cobertura {\n" +
" coverageFormats = ['xml', 'html']\n" +
" coverageSourceDirs = subprojects.sourceSets.main.allSource.srcDirs.flatten()\n" +
" coverageMergeDatafiles = files\n" +
"}\n" +
"\n" +
"test.finalizedBy(project.tasks.cobertura)\n" +
"jacoco {\n" +
" toolVersion = \"${jacocoVersion}\"\n" +
" reportsDir = file(\"$buildDir/reports\")\n" +
"}" +
"\n" +
"subprojects.each { project ->\n" +
" test.dependsOn(\":\" + project.name + \":test\")\n" +
"}\n" +
"task jacocoMergedReport(type: JacocoReport) {\n" +
" dependsOn = subprojects.jacocoTestReport\n" +
" additionalSourceDirs.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)\n" +
" sourceDirectories.setFrom files(subprojects.sourceSets.main.allSource.srcDirs)\n" +
" classDirectories.setFrom files(subprojects.sourceSets.main.output)\n" +
" executionData.setFrom project.fileTree(dir: '.', include: '**/build/jacoco/test.exec')\n" +
" reports {\n" +
" xml.enabled true\n" +
" csv.enabled false\n" +
" html.enabled true\n" +
" }\n" +
"}" +
"\n" +
"tasks.withType(JavaCompile) {\n" +
" options.compilerArgs = [\n" +
Expand Down Expand Up @@ -518,7 +520,7 @@ public static String getApplicationPropertiesContent(String nameProject) {
" h2:\n" +
" console:\n" +
" enabled: true\n" +
" path:/h2\n" +
" path: /h2\n" +
" profiles:\n" +
" include:\n";
}
Expand All @@ -528,11 +530,9 @@ public static String getMainApplicationContent(String packageName) {
return "package " + packageName + ";\n" +
"\n" +
"import org.springframework.boot.SpringApplication;\n" +
"import org.springframework.boot.autoconfigure.EnableAutoConfiguration;\n" +
"import org.springframework.boot.autoconfigure.SpringBootApplication;\n" +
"\n" +
"@SpringBootApplication\n" +
"@EnableAutoConfiguration()\n" +
"public class MainApplication {\n" +
"\n" +
" public static void main(String[] args) {\n" +
Expand All @@ -544,27 +544,19 @@ public static String getMainApplicationContent(String packageName) {
public static String getBuildGradleContent() {
return "buildscript {\n" +
"\text {\n" +
"\t\tcleanArchitectureVersion = '" + PluginTemplate.VERSION_PLUGIN + "'\n" +
"\t\tspringBootVersion = '2.1.1.RELEASE'\n" +
"\t\tspringCloudVersion = 'Greenwich.M1'\n" +
"\t\tsonarVersion = '"+SONAR_PLUGIN_VERSION+"'\n" +
"\t\tnetSalimanVersion = '"+NET_SALIMAN_COBERTURA_VERSION+"'\n" +
"\t}\n" +
"\trepositories {\n" +
"\t\tmavenCentral()\n" +
"\t\tmaven { url \"https://repo.spring.io/snapshot\" }\n" +
"\t\tmaven { url \"https://repo.spring.io/milestone\" }\n" +
"\t}\n" +
"\tdependencies {\n" +
"\t\tclasspath(\"org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}\")\n" +
"\t\tclasspath(\"org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:${sonarVersion}\")\n" +
"\t\tclasspath(\"net.saliman:gradle-cobertura-plugin:${netSalimanVersion}\")\n" +
"\t\tjacocoVersion = '" + JACOCO_TOOL_VERSION + "'\n" +
"\t}\n" +
"}\n" +
"\n" +
"plugins {\n" +
"\tid \"org.sonarqube\" version \""+SONAR_PLUGIN_VERSION+"\"\n" +
"\tid \"co.com.bancolombia.cleanArchitecture\" version \"" + PluginTemplate.VERSION_PLUGIN + "\"\n" +
"\tid \"net.saliman.cobertura\" version \""+NET_SALIMAN_COBERTURA_VERSION+"\" \n" +
"\tid 'co.com.bancolombia.cleanArchitecture' version \"${cleanArchitectureVersion}\"\n" +
"\tid 'org.springframework.boot' version \"${springBootVersion}\"\n" +
"\tid 'org.sonarqube' version \"${sonarVersion}\"\n" +
"\tid 'jacoco'\n" +
"}\n" +
"\n" +
"sonarqube {\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static String generateAzureDevOpsPipelineTemplateContent() {
" \n" +
" sonar.java.binaries=[Binaries]\n" +
" \n" +
" sonar.cobertura.reportPath=$(Build.SourcesDirectory)/build/reports/cobertura/coverage.xml\n" +
" sonar.coverage.jacoco.xmlReportPaths=$(Build.SourcesDirectory)/build/reports/jacocoMergedReport/jacocoMergedReport.xml\n" +
"\n" +
" sonar.coverage.exclusions=**/*Test.java,**/*.js,**/*.html,**/*.xml,**/*.css,**/app.demo/MainAplication.java,**/config/usecase/UseCaseConfig.java,**/config/jpa/JpaConfig.java,**/config/mongo/MongoConfig.java\n" +
" sonar.exclusions=**/aplications/app-service/src/**\n" +
Expand All @@ -70,7 +70,7 @@ public static String generateAzureDevOpsPipelineTemplateContent() {
" displayName: 'Gradle -> Build / Ejecutar Pruebas Unitarias'\n" +
" inputs:\n" +
" gradleWrapperFile: gradlew\n" +
" tasks: 'clean build --stacktrace'\n" +
" tasks: 'clean build jacocoMergedReport --stacktrace'\n" +
" publishJUnitResults: true\n" +
" workingDirectory: .\n" +
" testResultsFiles: '**/build/test-results/test/TEST-*.xml'\n" +
Expand Down

0 comments on commit 317055e

Please sign in to comment.