【发布时间】:2013-06-22 17:21:28
【问题描述】:
我正在创建一个本身具有依赖项 DEP 的 maven 插件。 DEP 可以是多个版本之一。我需要的是消费者必须明确提及 DEP 及其版本。我不希望消费者使用对 DEP 的隐式依赖,并在我发布新 DEP 时自动获取新版本。
这是我现在所拥有的,但这意味着如果消费者的 pom 中没有指定 DEP,那么他们将始终获得最新的。
在我的插件的依赖部分,我有这个:
<dependencies>
<dependency>
<groupId>org.foo.bar</groupId>
<artifactId>DEP</artifactId>
<version>[1.8.3-01,9.9.9)</version>
</dependency>
...
</dependencies>
然后,有人使用我的插件:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<compilerId>my-compiler-id/compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.foo.bar</groupId>
<artifactId>my-compiler</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
在上述情况下,一切都适用于消费者,他们总是获得最新版本的DEP。如果他们想要特定版本的 `DEP,那么他们需要在他们的 pom 中显式添加它,就像在 maven-compiler-plugin 的依赖项部分中一样:
<dependency>
<groupId>org.foo.bar</groupId>
<artifactId>DEP</artifactId>
<version>1.8.6-09</version>
</dependency>
现在,这个额外的显式依赖是可选的。如果缺少,则使用最新的。我想让这个依赖强制。我该怎么做?
【问题讨论】:
-
您想强制插件的用户定义
DEP和特定版本,而不是默认为最新版本? -
正确。这就是我需要的。
-
您希望构建失败吗?
-
是的。如果消费者的依赖关系不明确,则构建应该失败。理想情况下,如果出现有意义的错误会很好:“缺少 DEP 依赖项。请添加它...”,但这不是必需的。
-
您是否尝试在插件 pom 中将 DEP 声明为
<optional>?
标签: maven dependencies maven-plugin