0

我在几个地方尝试过如何使用 gradle 在 travis-ci 中配置 Codacy 的覆盖范围。

我发现如何在没有 travis-CI 的情况下配置 Gradle。我想做一些自动的事情。有人可以帮忙吗?

添加:

我的 build.gradle

buildscript {
    ext {
        springBootVersion = '2.0.5.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}


plugins {
    id "org.sonarqube" version "2.6"
    id 'com.gradle.build-scan' version '1.16'
}
configurations { codacy }
apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

group = 'com.rjdesenvolvimento'
version = '0.0.1'
sourceCompatibility = 1.11

repositories {
    mavenCentral()
}

tasks.withType(Test) { enabled = false }

dependencies {
    testImplementation 'junit:junit:4.12'
    compile group: 'org.hibernate', name: 'hibernate-core', version: '5.3.6.Final'
    implementation('org.springframework.boot:spring-boot-starter-data-jpa')
    implementation('org.springframework.boot:spring-boot-starter-security')
    implementation('org.springframework.boot:spring-boot-starter-web')
    runtimeOnly('org.springframework.boot:spring-boot-devtools')
    runtimeOnly('org.postgresql:postgresql')
    annotationProcessor("org.projectlombok:lombok:1.18.2")
    compileOnly('org.projectlombok:lombok')
    compileOnly('org.sonarsource.sonarqube:sonar-plugin-api:7.3')
    compileOnly('org.jacoco:org.jacoco.core:0.8.2')
    compileOnly('org.jacoco:org.jacoco.agent:0.8.2')
    compileOnly('com.codacy:codacy-coverage-reporter:5.0.310')
    testCompile group: 'com.h2database', name: 'h2', version: '1.4.197'
    testImplementation('org.springframework.boot:spring-boot-starter-test')
    testImplementation('org.springframework.security:spring-security-test')
    compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.4.0-b180830.0359'
    codacy 'com.github.codacy:codacy-coverage-reporter:-SNAPSHOT'
}

buildScan {
    termsOfServiceUrl = 'https://gradle.com/terms-of-service'
    termsOfServiceAgree = 'yes'
}

task sendCoverageToCodacy(type: JavaExec, dependsOn: jacocoTestReport) {
    main = "com.codacy.CodacyCoverageReporter"
    classpath = configurations.codacy
    args = [
            "report",
            "-l",
            "Java",
            "-r",
            "${buildDir}/reports/jacoco/test/jacocoTestReport.xml"
    ]
}

jacocoTestReport{
    additionalSourceDirs = files(sourceSets.main.allJava.srcDirs)
    reports {
        xml.enabled false
        csv.enabled false
        html.destination "${buildDir}/reports/jacoco/html"
    }
    executionData = files('build/jacoco/test.exec')
}

test {
    finalizedBy jacocoTestReport
}

和 travis.yml

env:
- CODACY_PROJECT_TOKEN=c8f9b1f6aab444018dd4e3...
language: java
install: true

jdk:
- oraclejdk11
before_install:
- chmod +x gradlew
- sudo apt-get install jq
- wget -O ~/codacy-coverage-reporter-assembly-latest.jar $(curl https://api.github.com/repos/codacy/codacy-coverage-reporter/releases/latest | jq -r '.assets[0].browser_download_url')

dist: trusty
before_cache:
- rm -f  $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
cache:
  directories:
  - $HOME/.gradle/caches/
  - $HOME/.gradle/wrapper/
addons:
sonarcloud:
  organization: "rjdesenvolvimento-github"
  token:
secure: 5150fa5cbf1f86006a140e0b8a96e...
script:
- ./gradlew build --scan -s sonarqube -Dsonar.projectKey=rjdesenvolvimento_apipessoas -Dsonar.organization=rjdesenvolvimento-github -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=5150fa5cbf1f86006a140e0b8a96e...

after_success:
- bash <(curl -s https://codecov.io/bash)>
  • java -jar ~/codacy-coverage-reporter-assembly-latest.jar 报告 -l Java -r build/reports/jacoco/test/jacocoTestReport.xml

还有 travis-ci

> Task :compileJava
> Task :processResources
> Task :classes
> Task :bootJar
> Task :jar SKIPPED
> Task :assemble
> Task :compileTestJava
> Task :processTestResources NO-SOURCE
> Task :testClasses
> Task :test SKIPPED
> Task :jacocoTestReport SKIPPED
> Task :check UP-TO-DATE
> Task :build
> Task :sonarqube
$ java -jar ~/codacy-coverage-reporter-assembly-latest.jar report -l Java -r build/reports/jacoco/test/jacocoTestReport.xml
10/24 23:51:49 INFO  c.c.rules.ConfigurationRules:101 - Using API base URL: https://api.codacy.com 
10/24 23:51:49 ERROR c.c.CodacyCoverageReporter$:28 - File /home/travis/build/rjdesenvolvimento/apipessoas/build/reports/jacoco/test/jacocoTestReport.xml does not exist. 

到目前为止还没有报道

4

2 回答 2

1

该解决方案似乎存在于文档中。

首先,您需要一个 gradle 任务。似乎有2个例子:https ://github.com/codacy/codacy-coverage-reporter/blob/master/README.md#gradle-task

然后您应该更新您的 travis-ci 步骤以在每次运行时自动发送覆盖率报告。与https://github.com/codacy/codacy-coverage-reporter/blob/master/README.md#travis-ci一起使用的东西,但使用您刚刚定义的 gradle 任务

于 2018-10-24T22:08:20.657 回答
1

您是否尝试过按照此处的说明创建 Gradle 任务?https://github.com/codacy/codacy-coverage-reporter/blob/master/README.md#gradle-task

于 2018-10-24T18:41:16.860 回答