如何将额外的类路径依赖项传递给 maven 中的 testCompile 阶段

Dis*_*sha 5 java maven maven-compiler-plugin

我想使用一些外部 jar 依赖项编译测试文件,这些依赖项不会出现在 pom.xml 的依赖项标记中。有没有办法通过配置。像这样的东西——

<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>
Run Code Online (Sandbox Code Playgroud)

小智 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>
Run Code Online (Sandbox Code Playgroud)