英文:
Cannot define absolute path in maven plugin
问题
我已经将surefire插件添加到Maven中,并需要将JAR文件添加到类路径以使测试正常工作。如果JAR文件与pom.xml在同一目录中,它可以正常工作:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>jooq-3.11.10.jar</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
但如果我定义绝对路径,它就找不到了。我需要指向JAR文件所在的位置。为什么会发生这种情况,如何使其工作?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<additionalClasspathElements>
<!-- 找不到这个JAR文件 -->
<additionalClasspathElement>c:\my\path\jooq-3.11.10.jar</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
英文:
I added the surefire plugin to maven, and need to add jars to the classpath for the tests to work. If the jar is in the same directory as pom.xml, it works fine:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>jooq-3.11.10.jar</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
But if I define the absolute path, it doesn't find it. I need to point the jar to the location where it is. Why does this happen and how to make this work?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<additionalClasspathElements>
// doesn't find this jar
<additionalClasspathElement>c:\my\path\jooq-3.11.10.jar</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
答案1
得分: 1
我建议使用类似以下的测试范围依赖项:
<!-- language:language-xml -->
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
<version>3.11.10</version>
<scope>test</scope>
</dependency>
这将自动将依赖项添加到仅用于测试的类路径上。无需在 maven-surefire-plugin 中手动添加此类内容。
英文:
I would suggest to use test scope dependencies like the following:
<!-- language:language-xml -->
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
<version>3.11.10</version>
<scope>test</scope>
</dependency>
That will add the dependency automatically on the classpath for testing only. There is no need to add things like that manually with path in maven-surefire-plugin.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论