从本地jar将自定义Maven插件安装到具有依赖项的本地存储库中 [英] Install custom maven plugin from local jar into local repository with dependencies

查看:196
本文介绍了从本地jar将自定义Maven插件安装到具有依赖项的本地存储库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Maven插件,我还没有上传到中央存储库,但是想在我的项目中使用.

I have a maven plugin, which I have not uploaded to the central repository, but which I want to use in my projects.

有效的方法

我可以这样安装Maven插件:

I can install the maven plugin like this:

git clone https://github.com/RudolfVonKrugstein/jinja-maven-plugin.git
cd jinja-maven-plugin
mvn install

然后我可以使用像pom.xml这样的插件:

Then I can use the plugin like this pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project>
    <modelVersion>4.0.0</modelVersion>

    <groupId>de.wintercloud</groupId>
    <artifactId>sample</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>de.wintercloud</groupId>
            <artifactId>jinja-maven-plugin</artifactId>
            <version>1.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>de.wintercloud</groupId>
                <artifactId>jinja-maven-plugin</artifactId>
                <version>1.0</version>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>renderjinja</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <outputFile>out.txt</outputFile>
                    <templateFile>templ.jinja</templateFile>
                    <varFile>vars.yaml</varFile>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

以下是与编译相关的其他文件:

Here are the other files relevant to the compile:

templ.jinja:

templ.jinja:

{{ Name }}

vars.yaml:

vars.yaml:

Name: MyWonderfullName

这有效:

> mvn compile
> cat out.txt 

我的名字

很好!

什么不起作用

现在,我正尝试将插件作为jar分发给我的同事,以便他们可以简单地安装jar.想法是这样做的:

Now I am trying to give the plugin as a jar to my colleagues so that they can simple install the jar. The Idea is to do it like this:

git clone https://github.com/RudolfVonKrugstein/jinja-maven-plugin.git
cd jinja-maven-plugin
mvn package
mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=target/jinja-maven-plugin-1.0.jar

现在执行操作(在示例项目目录中)

When I now do (in the sample project dir)

mvn compile

我收到此错误:

[ERROR] Failed to execute goal de.wintercloud:jinja-maven-plugin:1.0:renderjinja (default) on project sample: Execution default of goal de.wintercloud:jinja-maven-plugin:1.0:renderjinja failed: A required class was missing while executing de.wintercloud:jinja-maven-plugin:1.0:renderjinja: org/yaml/snakeyaml/Yaml

如何安装jar,以便可以将其用作插件? 在我看来,好像缺少依赖项.为什么?

How can I install the jar so that I can use it as a plugin? It looks to me as if dependencies are missing. Why?

推荐答案

您刚刚按下 MINSTALL -110 ,将在Maven安装插件的下一个3.0.0版本中修复.此处的核心问题是您要使用 file 参数,该插件检测到内部有POM,但仅保留坐标信息(组ID,工件ID,包装和版本),而不是整个POM.因此,在安装POM时,不会保留依赖项.

You just hit MINSTALL-110, which is going to be fixed in the next 3.0.0 release of the Maven Install Plugin. The core issue here is that you're installing manually a JAR file with the file parameter, the plugin detects that there is a POM inside, but only keeps the coordinate information (group id, artifact id, packaging and version), not the whole POM. As such, when the POM is installed, the dependencies aren't kept.

实际上,如果您查看已安装的POM,将会看到

Indeed, if you take a look at the installed POM, you will see

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>de.wintercloud</groupId>
  <artifactId>jinja-maven-plugin</artifactId>
  <version>1.0</version>
  <packaging>maven-plugin</packaging>
  <description>POM was created from install:install-file</description>
</project>

表示未保留依赖项.而且,如果您在运行install-file命令时以调试模式查看Maven日志,它将显示

which shows that the dependencies weren't retained. And if you take a look at the Maven logs in debug mode when running the install-file command, it will show

[DEBUG]使用META-INF/maven/de.wintercloud/jinja-maven-plugin/pom.xml来获取groupId,artifactId,打包和版本

[DEBUG] Using META-INF/maven/de.wintercloud/jinja-maven-plugin/pom.xml for groupId, artifactId, packaging and version

等待版本3.0.0的变通办法

A work-around waiting for version 3.0.0 is to specify the path to the POM file to install, along with the main artifact, by specifying the pomFile parameter. Run the following instead:

mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=target/jinja-maven-plugin-1.0.jar -DpomFile=pom.xml

然后将安装完整的POM,而不是通用存根.

Then the full POM will be installed, not a generic stub.

进行此更改后,会出现错误

With this change, the error

[错误]无法在项目样本上执行目标de.wintercloud:jinja-maven-plugin:1.0:renderjinja(默认值):目标de.wintercloud:jinja-maven-plugin:1.0:renderjinja的执行默认值失败:A执行de.wintercloud:jinja-maven-plugin:1.0:renderjinja:org/yaml/snakeyaml/Yaml时缺少必需的类

[ERROR] Failed to execute goal de.wintercloud:jinja-maven-plugin:1.0:renderjinja (default) on project sample: Execution default of goal de.wintercloud:jinja-maven-plugin:1.0:renderjinja failed: A required class was missing while executing de.wintercloud:jinja-maven-plugin:1.0:renderjinja: org/yaml/snakeyaml/Yaml

将不再发生. Maven将正确下载依赖项并将其用于插件.

will not happen anymore. Maven will correctly download the dependencies and use them for the plugin.

这篇关于从本地jar将自定义Maven插件安装到具有依赖项的本地存储库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆