问题标签 [maven-mojo]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
221 浏览

maven-plugin - 在我的自定义 Maven 插件中“找不到 mojo 错误”

我开发了一个自定义 Maven 插件,它有两个 Mojo。我从我的 IDE 中对其进行调试,其中一个目标运行良好,但找不到另一个目标。它说:

这是我的魔力:

工作一:

不工作:

可能是什么原因,有什么想法吗?

0 投票
2 回答
2954 浏览

maven - Maven Mojo 未知生命周期阶段

实际上我正在使用 maven 插件并创建自己的 maven 插件。

首先我遵循了本教程:http ://maven.apache.org/guides/plugin/guide-java-plugin-development.html但我意识到这不再起作用了,因为不知何故"org.apache.maven.plugins.annotations.Mojo"不存在!

之后我发现它现在应该如何工作。为此我创建了这个类:

我的 pom.xml 是这样的:

所以现在用 mvn de.sample.plugin:hello-maven-plugin:0.0.1-SNAPSHOT:hello 运行我的插件可以正常工作。但是使用这个:mvn de.sample.plugin:hello-maven-plugin:0.0.1-SNAPSHOT:hello hello.message="Test"会导致这个错误:

未知的生命周期阶段"hello.message=Test"。您必须指定有效的生命周期阶段或格式中的目标............

但它应该工作吗?有人可以帮忙吗?

0 投票
1 回答
377 浏览

maven - 如何解决maven插件在编译时生成的文件之间的依赖关系?

好的,让我尽量让我的问题不那么令人困惑。

我有一个带有一些 Maven 插件的标准 Maven 项目 -

现在这里是复杂的部分。

第一个插件生成一些 .java 文件,我目前将它们放在“ ${project.build.directory}/java ”中

第二个插件生成另一组 .java 文件,我将所有这些文件再次放在“ ${project.build.directory}/java ”下。但是,它们被放置在不同的包结构下。

这两个插件都在“ generate-sources ”阶段运行。

现在,我的第三个插件 jaxws-maven-plugin 尝试使用由第一个和第二个插件生成的文件的类文件,作为生成 WSDL 的 SEI。但是在编译期间,maven 不会创建类文件,并且插件会出错并显示“找不到类”消息。

那么我该如何解决这个问题呢?此外,由于我在“生成源”阶段出错,因此在 target/classes 目录中我的项目中看不到任何其他源文件的 .class 文件。

哦,这是另一个转折点。我的一些源文件在代码中导入这些编译时生成的源文件(你不知道我现在正在寻找这个开发人员有多糟糕!!)

我试图以最好的方式描述我的问题,所以请随时询问任何其他细节或澄清。

0 投票
2 回答
516 浏览

java - 如何从自定义 Mojo 中获取 maven 二进制版本?

我指的是您通常运行时返回的 maven 二进制版本

从返回如下输出的命令行,

注意 Maven 版本 3.0.4。从 Java 中的自定义 Maven Mojo 中访问它的最佳方法是什么?是否有可用的属性?

我想对正在执行我的 Mojo 的当前 maven 版本运行验证,谢谢

0 投票
3 回答
5482 浏览

maven - Maven 插件开发 - 如何确保为 Maven 3.0.x 而不是 3.1.x 构建?

我正在尝试开发一个自定义 Maven 插件。当我执行单元测试时,我目前遇到了这个问题:java.lang.NoClassDefFoundError: org.eclipse.aether.RepositorySystemSession堆栈跟踪如下:

根据我的研究,为 Maven 3.1.x 构建时会发生这种情况,因为 Maven 从 sonatype aether 实现切换到 eclipse 实现。

我正在尝试为 Eclipse 3.0.4构建我的插件,因为这是我们所有工作站上安装的。我假设我看到此错误是因为我的依赖项之一是 Maven 3.1.x 依赖项,尽管我不确定是哪一个。有谁知道我应该纠正哪个依赖?

另外,有谁知道是否可以构建一个适用于 Maven 3.0.x 和 3.1.x 的插件?当我们转向更新版本的 Maven 时,我宁愿在未来的某一天不必再经历这一切。

我的 POM 中的依赖项如下所示:

0 投票
0 回答
203 浏览

java - 将默认 Maven 项目注入其他 Maven 组件

我正在开发一个 Maven 插件,并使用 Assembly API 来做一些自定义的程序集构造。当我的代码运行时,我得到这个堆栈跟踪:

据我所知,这是由于DefaultAssemblyReader无法访问插件的默认 Maven 项目造成的。在我的 mojo 中,我已经像这样声明了 Maven 项目和程序集阅读器:

AssemblyReader 类没有任何设置器来设置项目,我不确定如何将project其注入到defaultReader. 我想到的一种解决方案是扩展SingleAssemblyMojo并为项目提供一个设置器,并将配置对象传递给程序集阅读器,但这似乎有点杂乱无章。有没有更优雅/正确的方法?

0 投票
2 回答
1334 浏览

java - Java Maven Mojo : Complex Map Attribute

The example of map attribute for a mojo mentioned in maven.apache.org is quite simple as it defines a Map with a String as a key and as a value as specified below :

and it's assigned configuration would look like this :

What I am trying to achieve is a more advanced map which takes a String as a key and my own defined class Person as value:

The Person class is located in the same package as my MOJO and it looks like:

I assume that the configuration for my MOJO would look like :

Running this MOJO with the above configuration will create the map with the defined keys but I always get null values : {firstPerson=null,secondPerson=null}

Currently, I don't know whether I am doing something wrong or if the example is even supported as no documentation has been found that describes an 'advanced' map attribute and my last resort for now would be browsing the sources.

0 投票
1 回答
1321 浏览

java - 从 Maven 调用 groovy 'main' 方法

我想在 Maven 的“包”阶段调用 groovy 类中的“主”方法。

我试过gmaven插件

但我得到一个“MissingPropertyException”

Groovy 文件看起来像

创建Deps.groovy

我可以使用 mojo 调用 java main 方法。我想使用 groovy 实现相同的结果。

提前致谢

0 投票
0 回答
124 浏览

java - How to access local maven repository in plexus component?

I am writing a custom DependencyAnalyzer which plugs into the dependency:analyze goal. The analyzer is a plexus component whose sole parameter is the MavenProject instance.

My analyzer needs access to the local repository to be able to invoke the DependencyTreeBuilder (from org.apache.maven.shared.dependency.tree), which is the same component used by dependency:tree in verbose mode.

I understand that in a mojo, I could use a parameter with the expression "${localRepository}" to get the required ArtifactRepository instance. However, I could not find a way to get the repository from the plexus component.

I managed to add a dependency to the ArtifactRepositoryFactory plexus component, but have no idea what to pass to its createArtifactRepository() method.

Is there any way to get the ArtifactRepository, or alternatively, a way to evaluate expressions from a plexus component?


Note: this is similar to How to get access to Maven's dependency hierarchy within a plugin, but the code given there applies to a mojo, whereas I need the code in a plexus component.

0 投票
1 回答
80 浏览

maven - Maven Mojo 是否具有等效于 ant 的 DirSet?

我正在将一个 ant 插件升级为 maven 插件,我的 ant 插件使用了DirSet,我看到 maven 只有一个FileSet

  • 我可以使用 FileSet 来收集目录吗?
  • 我是否应该通过查看 Ant 的 PatternSet - DirSet 代码然后使用 maven 的 PatternSet 和/或 FileSet 实现类似的解决方案来创建自己的 dirset 类?
  • 有没有更好的方法来收集包含和排除的目录?

谢谢您的帮助

彼得