代码之家  ›  专栏  ›  技术社区  ›  Jonathan

<常春藤:缓存路径>是慢,如何避免做它的每一个建设和提高常春藤cachepath性能?

  •  0
  • Jonathan  · 技术社区  · 6 年前

    我的编译时间会慢4秒 javac

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

    ivy:cachepath ${classpath} 在0.2秒内存在

    上下文: build.xml 哪一个引导ivy,使用 ivy.xml 列出标准maven依赖项的文件,然后调用 爪哇语 类路径中的lib)

        <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 回复  |  直到 6 年前
        1
  •  1
  •   Jonathan    6 年前

    这可能是一个愚蠢的方法,但我只是通过将类路径写入磁盘并将构建时间减半来强制实现一个解决方案:

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

    阅读方式:

        <loadproperties srcFile="my.properties"/>
    

    使用途径:

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

    如果是这样的话,速度可能会更快 <echo file= 任务