2016-11-22 55 views
4

我想使用一些外部jar依賴項編譯測試文件,這些依賴項不會出現在pom.xml的依賴項標記中。有沒有辦法通過配置。像這個 -如何將其他類路徑依賴項傳遞給maven中的testCompile階段

<plugin> 
    <artifactId>maven-compiler-plugin</artifactId> 
    <configuration> 
    <source>1.5</source> 
    <target>1.5</target> 
    </configuration> 
    <executions> 
    <execution> 
     <id>test-compile</id> 
     <configuration> 
     <classPathElements> 
      <classPathElement>somejar.jar</classPathElement> 
     </classPathElements> 
     </configuration> 
    </execution> 

    </executions> 
</plugin> 
+1

只是一個小問題庫。您是否需要使用外部JAR編譯測試類,或者是否需要使用外部JAR執行測試? –

+0

其實這兩個,但爲執行我使用maven-surefire-plugin ..其中有選項可以使用標記傳遞外部瓶子 – Disha

+0

你爲什麼要嘗試這樣做? (除了你不能的事實)。 – Tunaki

回答

0

東西試試這個,它包括從項目

<dependency> 
     <groupId>mylib</groupId> 
     <artifactId>com.mylib</artifactId> 
     <version>1.0</version> 
     <scope>system</scope> 
     <systemPath>${project.basedir}/src/main/resources/mylib.jar</systemPath> 
</dependency>