无法在Maven插件中定义绝对路径

huangapple go评论55阅读模式
英文:

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:

	&lt;plugin&gt;
		&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
		&lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
		&lt;version&gt;3.0.0-M5&lt;/version&gt;
		&lt;configuration&gt;
			&lt;additionalClasspathElements&gt;
				&lt;additionalClasspathElement&gt;jooq-3.11.10.jar&lt;/additionalClasspathElement&gt;
				&lt;/additionalClasspathElements&gt;
		&lt;/configuration&gt;
	&lt;/plugin&gt;

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?

	&lt;plugin&gt;
		&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
		&lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
		&lt;version&gt;3.0.0-M5&lt;/version&gt;
		&lt;configuration&gt;
			&lt;additionalClasspathElements&gt;

                // doesn&#39;t find this jar
				&lt;additionalClasspathElement&gt;c:\my\path\jooq-3.11.10.jar&lt;/additionalClasspathElement&gt;

			&lt;/additionalClasspathElements&gt;
		&lt;/configuration&gt;
	&lt;/plugin&gt;

答案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 -->

&lt;dependency&gt;
  &lt;groupId&gt;org.jooq&lt;/groupId&gt;
  &lt;artifactId&gt;jooq&lt;/artifactId&gt;
  &lt;version&gt;3.11.10&lt;/version&gt;
  &lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;

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.

huangapple
  • 本文由 发表于 2020年7月26日 18:17:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/63098802.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定