<ivy:cachepath> is SLOW, how to avoid doing it every build and improve ivy cachepath performance?

安稳与你 提交于 2020-01-11 14:10:31

问题


Compile times are slowed by 4s resolving dependant libs for my javac step every build on this line:

    <target name="compile" depends="bootstrap">
        <ivy:cachepath pathid="classpath"/> <!-- SLOW -->

I want to essentially CACHE the results of ivy:cachepath so I don't have to do it every build. I want ${classpath} to exist in less than 0.2 seconds

Context: This is a vanilla ant build.xml which bootstraps ivy, uses an ivy.xml file that lists standard maven dependencies, then calls javac with those libs in a class path)

    <property name="ivy.install.version" value="2.4.0"/>
    <property name="ivy.jar.dir" value="${basedir}/ivy"/>
    <property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar"/>
    <property name="build.dir" value="build"/>
    <property name="src.dir" value="src"/>
    <target name="bootstrap" description="--> install ivy">
        <path id="ivy.lib.path">
            <fileset dir="${ivy.jar.dir}" includes="*.jar"/>
        </path>
        <taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
    </target>

    <!-- Download any missing libs -->
    <target name="install" depends="bootstrap">
        <!-- install ivy.jar -->
        <mkdir dir="${ivy.jar.dir}"/>
        <echo message="installing ivy..."/>
        <get src="https://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar" dest="${ivy.jar.file}" usetimestamp="true"/>
        <!-- Downloads all the libraries from maven central via ivy.xml and saves them to classpath-->
        <ivy:settings file="ivysettings.xml"/>
        <ivy:resolve/>
        <ivy:retrieve sync="true"
                      type="jar,bundle"/>
        <ivy:cachepath pathid="classpath"/>
    </target>

  <target name="clean" depends="bootstrap">
        <delete dir="${build_dir}"/>
        <delete dir="./lib"/>
        <delete dir="./bin"/>
        <ivy:cleancache/>
  </target>


    <!-- Compile -->
    <target name="compile" depends="bootstrap">
        <ivy:cachepath pathid="classpath"/>
        <ivy:settings file="ivysettings.xml"/>
        <mkdir dir="${build_dir}"/>
        <javac encoding="ISO-8859-1"
               includeantruntime="false"
               srcdir="${src_dir}"
               destdir="${build_dir}"
               classpathref="classpath"
               debug="on">
            <!--<withKotlin/> &lt;!&ndash; If this is undefined, run "Build" target first. &ndash;&gt;-->
        </javac>
        <!--<kotlinc src="${src_dir}/TestSuite/TestSuite.java" output="${build_dir}/${jar_name}.jar"/>-->

        <delete file="${dist_dir}/${jar_name}.jar"/>

        <pathconvert property="classpath.name" pathsep=" ">
            <path refid="classpath" />
            <mapper>
                <chainedmapper>
                    <flattenmapper />
                    <globmapper from="*.jar" to="../lib/*.jar" />
                </chainedmapper>
            </mapper>
        </pathconvert>

        <echo message="classpath.name : ${classpath.name} " />
        <jar destfile="bin/${jar_name}.jar" basedir="build" includes="**/*.class lib/*">
            <manifest>
                <attribute name="Main-Class" value="${main-class}"/>
                <attribute name="Class-Path" value="${classpath.name}"/>
            </manifest>
        </jar>
    </target>

回答1:


This is probably a stupid way to do it, but I just brute forced a solution by writing classpath to disk and cut build times in half:

Write via:

    <pathconvert property="classpath">
        <path refid="classpath" />
    </pathconvert>
    <propertyfile file="my.properties" comment="My properties">
        <entry key="classpath" value="${classpath}"/>
    </propertyfile>

Read via:

    <loadproperties srcFile="my.properties"/>

Use via:

    <javac classpath="${classpath}" ... >

It may have been even faster with the <echo file= task



来源:https://stackoverflow.com/questions/53622640/ivycachepath-is-slow-how-to-avoid-doing-it-every-build-and-improve-ivy-cache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!