1

我正在使用mojo-executor库从另一个 Maven 插件中调用许多 Maven 插件。

但是,当我调用它们时,我找不到任何方法来指定对插件的依赖关系。这是一个问题maven-assembly-plugin,我需要添加一个程序集描述符文件作为依赖项。在另一个级别添加依赖项似乎不会将描述符文件放到插件的类路径中。

知道这是否可能,或者是否可以改进 mojo-executor 以提供此功能?谢谢。

4

3 回答 3

2

mojo-executor 将在没有任何类路径的环境中执行 mojo。您需要手动添加依赖项。

Dependency dep = new Dependency();  
dep.setGroupId("groupId");
dep.setArtifactId("artifactId");
dep.setVersion("0.0.1-SNAPSHOT");

Plugin assembly = MojoExecutor.plugin(
   "org.apache.maven.plugins", 
   "maven-assembly-plugin", 
   "2.3");

assembly.addDependency(dep)

MojoExecutor.executeMojo(assembly,
   MojoExecutor.goal("single"),
   ...
)
于 2012-06-21T12:38:58.143 回答
0

您知道也可以为插件定义依赖项:

 <plugin>
    <groupId>com.soebes.maven.plugins.mlv</groupId>
    <artifactId>maven-license-verifier-plugin</artifactId>
    <version>0.4</version>
    <dependencies>
      <dependency>
        <groupId>com.company.licenses</groupId>
        <artifactId>allprojects</artifactId>
        <version>1.0</version>
      </dependency
    </dependencies>
    <configuration>
      <!-- Optional you can put your configurations here -->
    </configuration>
  </plugin>

这会将依赖项放在插件的类路径上。那可能会解决你的问题。

于 2012-06-07T18:06:08.783 回答
0

也许您需要在我们的 Maven 插件目标类的 @Mojo 注释中放置一个 requiresDependencyResolution 参数。像这样的东西:

@Mojo(name = "your-goal", defaultPhase = LifecyclePhase.xxx,
  requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME
)
public class YourGoalMojo...

这对于您的 Maven 插件在执行之前/执行之前解析和可用的依赖项是必要的。mojo-executor 项目的 README 页面在其基于 maven-dependency-plugin 的示例之后提到了这一点:

可以在此处找到有关 @Mojo 注释参数化的更多信息:

于 2013-12-04T14:11:46.743 回答