使用依赖项将本地 jar 中的自定义 Maven 插件安装到本地存储库
Install custom maven plugin from local jar into local repository with dependencies
我有一个maven插件,我还没有上传到中央仓库,但我想在我的项目中使用它。
有效方法
我可以这样安装maven插件:
git clone https://github.com/RudolfVonKrugstein/jinja-maven-plugin.git
cd jinja-maven-plugin
mvn install
然后我可以像这样使用插件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>
以下是与编译相关的其他文件:
templ.jinja:
{{ Name }}
vars.yaml:
Name: MyWonderfullName
这个有效:
> mvn compile
> cat out.txt
我的名字
不错!
什么不起作用
现在我正尝试将插件作为 jar 提供给我的同事,以便他们可以简单地安装 jar。我的想法是这样做:
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
当我现在做的时候(在示例项目目录中)
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 以便我可以将其用作插件?
在我看来,好像缺少依赖项。为什么?
您只点击了 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(组 ID、工件 ID、打包和版本),而不是整个 POM。因此,安装 POM 时,不会保留依赖项。
的确,如果你看一下安装的 POM,你会看到
<?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 日志,它将显示
[DEBUG] Using META-INF/maven/de.wintercloud/jinja-maven-plugin/pom.xml for groupId, artifactId, packaging and version
等待版本 3.0.0 is to specify the path to the POM file to install, along with the main artifact, by specifying the pomFile
参数的解决方法。 运行 改为:
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,而不是通用存根。
有了这个改变,错误
[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 将正确下载依赖项并将它们用于插件。
我有一个maven插件,我还没有上传到中央仓库,但我想在我的项目中使用它。
有效方法
我可以这样安装maven插件:
git clone https://github.com/RudolfVonKrugstein/jinja-maven-plugin.git
cd jinja-maven-plugin
mvn install
然后我可以像这样使用插件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>
以下是与编译相关的其他文件:
templ.jinja:
{{ Name }}
vars.yaml:
Name: MyWonderfullName
这个有效:
> mvn compile
> cat out.txt
我的名字
不错!
什么不起作用
现在我正尝试将插件作为 jar 提供给我的同事,以便他们可以简单地安装 jar。我的想法是这样做:
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
当我现在做的时候(在示例项目目录中)
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 以便我可以将其用作插件? 在我看来,好像缺少依赖项。为什么?
您只点击了 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(组 ID、工件 ID、打包和版本),而不是整个 POM。因此,安装 POM 时,不会保留依赖项。
的确,如果你看一下安装的 POM,你会看到
<?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 日志,它将显示
[DEBUG] Using META-INF/maven/de.wintercloud/jinja-maven-plugin/pom.xml for groupId, artifactId, packaging and version
等待版本 3.0.0 is to specify the path to the POM file to install, along with the main artifact, by specifying the pomFile
参数的解决方法。 运行 改为:
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,而不是通用存根。
有了这个改变,错误
[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 将正确下载依赖项并将它们用于插件。