使用 Ant 将 JaCoCo 集成到声纳中 [英] integrating JaCoCo in sonar using Ant

查看:23
本文介绍了使用 Ant 将 JaCoCo 集成到声纳中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我坚持使用 Ant 将 JaCoCo 与声纳集成.这项任务非常新,并且是第一次集成.我浏览了很多链接,例如

I am stuck integrating JaCoCo with sonar using Ant. Very new to this task, and integrating for the first time. I have gone through many links like

我正在尝试在另一个 VM 上显示结果,而代码在我的 VM 中.获取与 JDK6、VM 相关的各种错误,并且无法分析我的包结构我的问题是我是否需要定义任何特定的项目属性,除了上面的 VM 链接中给出的等等我还想包括我的 checkstyle 和 findbugs 就像魅力一样工作.只需要集成JaCoCo.任何信息都会有很大帮助.

I am trying to display result on another VM, and code is in my VM. Getting all sorts of errors related to JDK6,VM, and not able to analyze my package structure My que is do I need to define any specific project properties beside given in the above links for VM etc I would also like to include that my checkstyle, and findbugs is working like charm. Only need to integrate JaCoCo. Any information will be of great help.

如果发现我的描述不符合我的要求,请询问

If found my description is not up to my mark, kindly ask

感谢帮助

推荐答案

以下是配置为运行 junit 单元测试并使用 jacoco 进行代码覆盖率报告的 ANT 构建.结果上传到Sonar,最后用ivy下载3rd party jars和管理classpaths.

The following is an ANT build that is configured to run a junit unit test and use jacoco for code coverage reporting. The results are uploaded to Sonar and finally ivy is used to download 3rd party jars and manage classpaths.

├── build.properties
├── build.xml
├── ivy.xml
└── src
    ├── main
    │   └── java
    │       └── org
    │           └── demo
    │               └── App.java
    └── test
        └── java
            └── org
                └── demo
                    └── AppTest.java

build.properties

# Build properties
build.dir=build

src.dir=src/main/java
test.src.dir=src/test/java

classes.dir=${build.dir}/classes
test.classes.dir=${build.dir}/test-classes

reports.dir=${build.dir}/reports

# Sonar properties
sonar.projectKey=org.demo:demo
sonar.projectName=Demo project
sonar.projectVersion=1.0
sonar.projectDescription=This is my demo Sonar project

sonar.host.url=http://localhost:9000

sonar.jdbc.url=jdbc:h2:tcp://localhost:9092/sonar
sonar.jdbc.driverClassName=org.h2.Driver
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar

sonar.working.directory=${build.dir}/sonar

sonar.language=java
sonar.sources=${src.dir}
sonar.binaries=${classes.dir}
sonar.tests=${test.src.dir}

sonar.dynamicAnalysis=reuseReports
sonar.surefire.reportsPath=${reports.dir}/junit
sonar.java.coveragePlugin=jacoco
sonar.jacoco.reportPath=${build.dir}/jacoco.exec

build.xml

<project name="demo" default="test" xmlns:ivy="antlib:org.apache.ivy.ant">

    <property file="build.properties"/>

    <target name="bootstrap" description="Install ivy">
        <mkdir dir="${user.home}/.ant/lib"/>
        <get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.3.0/ivy-2.3.0.jar"/>
    </target>

    <target name="resolve" description="Download dependencies and setup classpaths">
        <ivy:resolve/>
        <ivy:report todir='${reports.dir}/ivy' graph='false' xml='false'/>

        <ivy:cachepath pathid="compile.path" conf="compile"/>
        <ivy:cachepath pathid="test.path"    conf="test"/>
        <ivy:cachepath pathid="build.path"   conf="build"/>
    </target>

    <target name="init" depends="resolve" description="Create build directories">
        <mkdir dir="${classes.dir}"/>
        <mkdir dir="${test.classes.dir}"/>
        <mkdir dir="${reports.dir}/junit"/>
    </target>

    <target name="compile" depends="init" description="Compile source code">
        <javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="false" debug="true" classpathref="compile.path"/>
    </target>

    <target name="compile-tests" depends="compile" description="Compile test source code">
        <javac srcdir="${test.src.dir}" destdir="${test.classes.dir}" includeantruntime="false" debug="true">
            <classpath>
                <path refid="test.path"/>
                <pathelement path="${classes.dir}"/>
            </classpath>
        </javac>
    </target>

    <target name="test" depends="compile-tests" description="Run unit tests and code coverage reporting">
        <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml" classpathref="build.path"/>

        <jacoco:coverage destfile="${build.dir}/jacoco.exec" xmlns:jacoco="antlib:org.jacoco.ant">
            <junit haltonfailure="yes" fork="true">
                <classpath>
                    <path refid="test.path"/>
                    <pathelement path="${classes.dir}"/>
                    <pathelement path="${test.classes.dir}"/>
                </classpath>
                <formatter type="plain" usefile="false" />
                <formatter type="xml"/>
                <batchtest fork="yes" todir="${reports.dir}/junit">
                    <fileset dir="${test.src.dir}">
                        <include name="**/*Test*.java"/>
                        <exclude name="**/AllTests.java"/>
                    </fileset>
                </batchtest>
            </junit>
        </jacoco:coverage>
    </target>

    <target name="sonar" depends="test" description="Upload metrics to Sonar">
        <taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml" classpathref="build.path"/>

        <ivy:cachepath pathid="sonar.libraries" conf="compile"/> 

        <sonar:sonar xmlns:sonar="antlib:org.sonar.ant"/>
    </target>

    <target name="clean" description="Cleanup build files">
        <delete dir="${build.dir}"/>
    </target>

    <target name="clean-all" depends="clean" description="Additionally purge ivy cache">
        <ivy:cleancache/>
    </target>

</project>

ivy.xml

<ivy-module version="2.0">
    <info organisation="com.myspotontheweb" module="demo"/>

    <configurations defaultconfmapping="compile->default">
        <conf name="compile" description="Required to compile application"/>
        <conf name="test"    description="Required for test only" extends="compile"/>
        <conf name="build"   description="Build dependencies"/>
    </configurations>

    <dependencies>
        <!-- compile dependencies -->

        <!-- test dependencies -->
        <dependency org="junit" name="junit" rev="4.10" conf="test->default"/>

        <!-- build dependencies -->
        <dependency org="org.codehaus.sonar-plugins" name="sonar-ant-task" rev="2.1" conf="build->default"/>
        <dependency org="org.jacoco" name="org.jacoco.ant" rev="0.6.3.201306030806" conf="build->default"/>

        <!-- Global exclusions -->
        <exclude org="org.apache.ant"/>
    </dependencies>

</ivy-module>

这篇关于使用 Ant 将 JaCoCo 集成到声纳中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆