【发布时间】:2013-06-03 19:32:43
【问题描述】:
我创建了一个 Maven 插件(称为 unpackTemplates),它解压缩依赖项 jar 文件并将其中的资源文件(在本例中为模板)复制到项目中的特定位置。
现在,我将以下内容放入每个与模板有依赖关系的项目的 pom 文件中。它看起来像:
<project>
<groupId>DuriansAreDope</groupId>
<artifactId>DuriansAreDope</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugin>
<groupId>mycorp</groupId>
<artifactId>unpackTemplates</artifactId>
<version>1.0</version>
<executions>
<execution>
<configuration>
<groupId>com.mycorp.lib</groupId>
<version>1.0</version>
<artifactId>Lib-With-Templates</artifactId>
</configuration>
<goals>
<goal>unpackTemplates</goal>
</goals>
<phase>generate-sources</phase>
</execution>
</executions>
</plugin>
<pluginManagement>....</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>com.mycorp.lib</groupId>
<artifactId>Lib-With-Templates</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
上述项目 pom 为我们工作。它调用插件,插件完成它的工作。但是,我们希望避免将插件部分添加到每个项目的 pom 中。
将插件部分放在依赖项 pom.xml 中会更有意义。这样,除了像往常一样添加<dependency>标签之外,不需要修改项目pom。并且依赖项的插件在安装的任何地方都可以运行。
我看到 Gson 的 pom 文件中包含一个 <build><plugins>...</plugins></build> 部分。但是,当我将以下 pom 文件提供给我的依赖项时,该插件未运行(尽管已正确找到、下载、安装等依赖项)。
<project>
<groupId>com.mycorp.lib</groupId>
<artifactId>Lib-With-Templates</artifactId>
<version>1.0</version>
<build>
<plugin>
<groupId>mycorp</groupId>
<artifactId>unpackTemplates</artifactId>
<version>1.0</version>
<executions>
<execution>
<configuration>
<groupId>com.mycorp.lib</groupId>
<version>1.0</version>
<artifactId>Lib-With-Templates</artifactId>
</configuration>
<goals>
<goal>unpackTemplates</goal>
</goals>
<phase>generate-sources</phase>
</execution>
</executions>
</plugin>
<pluginManagement>....</pluginManagement>
</build>
</project>
任何想法我做错了什么,或者如果 Gson pom 只是完全在做其他事情?
(注意:<configuration> 中的 groupId/version/artifactIds 是必需的,因为它们是插件的(字符串)参数;大概如果我让 run-straight-from-dependency 方法起作用,我可以将它们重构掉,但是同样,它甚至没有运行带有参数的 kludgy 版本。)
【问题讨论】:
-
除了你的插件你知道kind of plugin already exists?。可能是我疏忽了某些事情,但我不确定您的问题到底是什么?因为您写了
It would make more sense to have the library know that the last step of its installation is to run the plugin.,但是您在谈论哪个库。也许你可以详细说明一下。 -
谢谢@khmarbaise。我们找到了 maven“解包”插件,但没有找到您链接到的“远程资源”插件。从参数的结构来看,我会说它们都做类似的事情:将文件从依赖项复制到您的项目中。但是,我们需要对文件有更多的控制权:我们需要重命名它们并将它们放到特定的位置。
-
@khmarbaise:详细说明最后一点:我们不想将调用插件添加到项目中,而是将其添加到依赖项本身。我们希望这意味着插件可以在安装依赖项的任何地方运行,而项目不需要知道插件或如何调用它。
标签: maven maven-plugin m2eclipse m2e