加入蚂蚁动态插件在生成时? [英] Add ant plugins dynamically at buildtime?

查看:217
本文介绍了加入蚂蚁动态插件在生成时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个Ant构建,在构建时拉低它的插件。因此,举例来说,如果用我的构建 FindBugs的的Checkstyle JAR文件,并呼吁他们的任务从内build.xml文件,那么最好我可以:

I'd like to set up an Ant build that pulls down its plugins at buildtime. So for instance, if my build used findbugs and checkstyle JARs and called their tasks from inside build.xml, then ideally I could:


  1. 运行的常春藤解析常春藤提取任务拉 FindBugs的的Checkstyle JAR文件分解成,比方说,根/ lib中/编译期

  2. 添加根/ lib中/编译期来Ant的类路径

  3. 定义<任务定义> 定义各种 FindBugs的的Checkstyle 任务

  4. 在下游目标执行 FindBugs的的Checkstyle 任务

  1. Run an ivy-resolve and ivy-retrieve task to pull findbugs and checkstyle JARs down into, say, gen/lib/buildtime.
  2. Add gen/lib/buildtime to Ant's classpath
  3. Define <taskdefs> that define the various findbugs and checkstyle tasks
  4. Execute the findbugs and checkstyle tasks in a downstream target

这可能吗?如果是这样,怎么样?我觉得这里的唯一表明,塞的是,我不认为你可以动态地添加&LT的事实;任务定义&GT;!提前 ...谢谢

Is this possible? If so, how? I think the only show-stopper here is the fact that I don't think you can dynamically add <taskdefs>... thanks in advance!

推荐答案

最好的办法是使用的 cachepath 任务来填充需要的jar的ANT路径。然后,您的taskdef变为:

The best approach is to use the cachepath task to populate an ANT path with the required jars. Your taskdef then becomes:

<ivy:cachepath pathid="build.path" conf="build"/>
<taskdef uri="antlib:org???" resource="???" classpathref="build.path"/>

这是常春藤配置可以用来控制罐子应该填充路径

An ivy configuration can be used to control which jars should populate the path.

下面的示例使用声纳自动运行的FindBugs和Checkstyle的。它演示了如何使用常春藤在以下ANT插件拉:

The following example uses Sonar to run findbugs and checkstyle automatically. It demonstrates using ivy to pull in the following ANT plugins:


  • 的JUnit

  • 声纳

  • jacoco

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

的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>

的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>

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

这篇关于加入蚂蚁动态插件在生成时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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