2014-11-20 82 views
1

我目前有一個Maven構建,它調用一個ant任務來運行。這個ant任務依賴於一些外部庫。這些庫目前在我的系統中進行了硬編碼。我想將這些外部庫移動到本地Maven庫,並讓maven從回購庫中檢索它們,但不知道如何執行此操作。如何在ant maven任務中使用外部lib /依賴項?

我現在的任務定義爲(編輯爲簡潔的全任務定義):

 <plugin> 
      <artifactId>maven-antrun-plugin</artifactId> 
      <executions> 

       <!-- Ant Custom Folder copying plugin --> 
       <execution> 
        <id>rename_files</id> 
        <phase>process-resources</phase> 
        <configuration> 
         <tasks> 
          <taskdef resource="net/sf/antcontrib/antlib.xml" classpath="${env.ANT_HOME}/lib/ant-contrib-1.0b3.jar" /> 
          <taskdef name="stringutil" classname="ise.antelope.tasks.StringUtilTask" classpath="${env.ANT_HOME}/lib/AntelopeTasks_3.4.1.jar" /> 
          <typedef name="trim" classname="ise.antelope.tasks.typedefs.string.Trim" classpath="${env.ANT_HOME}/lib/AntelopeTasks_3.4.1.jar" /> 
          <typedef name="lastindexof" classname="ise.antelope.tasks.typedefs.string.LastIndexOf" classpath="${env.ANT_HOME}/lib/AntelopeTasks_3.4.1.jar" /> 
          <typedef name="substring" classname="ise.antelope.tasks.typedefs.string.Substring" classpath="${env.ANT_HOME}/lib/AntelopeTasks_3.4.1.jar" /> 
          <typedef name="listfiles" classname="ise.antelope.tasks.typedefs.file.FileList" classpath="${env.ANT_HOME}/lib/AntelopeTasks_3.4.1.jar" /> 
          <taskdef name="fileutil" classname="ise.antelope.tasks.FileUtilTask" classpath="${env.ANT_HOME}/lib/AntelopeTasks_3.4.1.jar" /> 

          <!-- CSS --> 
          <for param="file"> 
           <path> 
            <fileset dir="target\Com-${project.version}\style\" includes="*.css" /> 
           </path> 
           <sequential> 
            <fileutil file="@{file}" property="fileWithoutPath"> 
             <listfiles includepath="false" /> 
            </fileutil> 
           </sequential> 
          </for> 
         </tasks> 
        </configuration> 
        <goals> 
         <goal>run</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 

我知道我可以定義<dependencies>爲我的插件的一部分閃避,但不知道如何重新定義我的taskdef點到依賴與rar jar文件。

回答

2

經過篩選,我發現我可以做到以下幾點。

 <plugin> 
      <artifactId>maven-antrun-plugin</artifactId> 
      <dependencies> 
       <dependency> 
        <groupId>ant-contrib</groupId> 
        <artifactId>ant-contrib</artifactId> 
        <version>1.0b3</version> 
       </dependency> 
       <dependency> 
        <groupId>org.tigris.antelope</groupId> 
        <artifactId>antelopetasks</artifactId> 
        <version>3.4.1</version> 
       </dependency> 
      </dependencies> 
      <executions> 

       <!-- Ant Custom Folder copying plugin --> 
       <execution> 
        <id>rename_files</id> 
        <phase>process-resources</phase> 
        <configuration> 
         <tasks> 
          <taskdef resource="net/sf/antcontrib/antlib.xml" classpathref="maven.plugin.classpath" /> 
          <taskdef name="stringutil" classname="ise.antelope.tasks.StringUtilTask" classpathref="maven.plugin.classpath" /> 
          <typedef name="trim" classname="ise.antelope.tasks.typedefs.string.Trim" classpathref="maven.plugin.classpath" /> 
          <typedef name="lastindexof" classname="ise.antelope.tasks.typedefs.string.LastIndexOf" classpathref="maven.plugin.classpath" /> 
          <typedef name="substring" classname="ise.antelope.tasks.typedefs.string.Substring" classpathref="maven.plugin.classpath" /> 
          <typedef name="listfiles" classname="ise.antelope.tasks.typedefs.file.FileList" classpathref="maven.plugin.classpath" /> 
          <taskdef name="fileutil" classname="ise.antelope.tasks.FileUtilTask" classpathref="maven.plugin.classpath" /> 

        </tasks> 
       </configuration> 
       <goals> 
        <goal>run</goal> 
       </goals> 
      </execution> 
     </executions> 
    </plugin> 

只需在任務DEFN使用classpathref並指向maven.plugin.classpath

希望這有助於未來的其他人。

相關問題