简体   繁体   English

Maven插件依赖性

[英]Maven plugin dependencies

I haven't been able to find an answer specifically regarding this problem. 我还没有找到专门针对此问题的答案。

I've successfully installed a patched maven plugin jar file manually (osxappbundle) using the following: 我已经使用以下命令成功手动安装了补丁的maven插件jar文件(osxappbundle):

mvn install:install-file -Dfile=osxappbundle-maven-plugin-1.0-alpha-4-SNAPSHOT.jar -Dpackaging=jar -DgroupId=org.codehaus.mojo -DartifactId=osxappbundle-maven-plugin -Dversion=1.0-alpha-4-SNAPSHOT -DgeneratePom=true

When the plugin is referred to in the pom, specifically 'bundle', I receive the error: 当在pom中,特别是在“ bundle”中引用插件时,我收到错误消息:

Unable to load the mojo 'bundle' in the plugin 'org.codehaus.mojo:osxappbundle-maven-plugin:1.0-alpha-4-SNAPSHOT'. 无法在插件“ org.codehaus.mojo:osxappbundle-maven-plugin:1.0-alpha-4-SNAPSHOT”中加载mojo“ bundle”。 A required call is missing: org/apache/velocity/exception/MethodInvocationException. 缺少必需的调用:org / apache / velocity / exception / MethodInvocationException。

org.apache.velocity is definitely installed and is in my local respository (.m2) but isn't found. org.apache.velocity确实已安装,并且在我的本地存储库(.m2)中,但未找到。 If I manually add the class files into the jar they are found, so this suggests it's not resolving dependencies using the local repository. 如果我将类文件手动添加到jar中,则可以找到它们,因此这表明它不是在使用本地存储库来解决依赖关系。

I assume this is happening because I manually installed the jar file. 我认为发生这种情况是因为我手动安装了jar文件。

If a jar is manually installed, will it only resolve the dependencies if they are in the jar and not look outside? 如果手动安装了jar,那么仅当它们在jar中并且不在外部时,它才会解析依赖项吗?

The plugin is referenced in the pom like this: 插件在pom中的引用如下:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>osxappbundle-maven-plugin</artifactId>
    <version>1.0-alpha-4-SNAPSHOT</version>
    <configuration>
    </configuration>
    <executions>
        <execution>
            <phase>package</phase>
                <goals>
                    <goal>bundle</goal>
                </goals>
        </execution>
    </executions>
</plugin>

Plugins are handled the same way as project dependencies. 插件的处理方式与项目依赖项相同。 Whatever dependencies the original plugin refer to in its pom.xml are put on the classpath at runtime. 原始插件在其pom.xml中引用的所有依赖项都将在运行时放在类路径中。

It is usually sufficient to change the <version> tag in the pom.xml of the plugin and run mvn install . 通常只需更改插件的pom.xml中的<version>标记并运行mvn install This will install the jar and pom file to your local repository. 这会将jar和pom文件安装到本地存储库。 Use a version which makes clear that it is not an official one, eg 1.2.3-CUSTOM-SNAPSHOT . 使用一个明确表明不是官方版本的版本,例如1.2.3-CUSTOM-SNAPSHOT Then change the dependency to this version in your application's pom file and it should work as expected. 然后在应用程序的pom文件中将此版本的依赖项更改为它,它应能按预期工作。

If you must use invoke install plugin directly for any reasons, you should always install a proper pom.xml with your jar file. 如果出于任何原因必须直接使用invoke install插件,则应始终在jar文件中安装适当的pom.xml Use -DpomFile=/path/to/pom.xml to specify the path to the correct pom of your plugin. 使用-DpomFile=/path/to/pom.xml来指定插件正确pom的路径。 -DgeneratePom=true will generate only a minimalistic pom if there isn't already a pom.xml for this artifact and version in the repository. 如果存储库中没有此工件和版本的pom.xml ,则-DgeneratePom=true将仅生成简约的pom。 This pom file won't specify any dependencies. 此pom文件不会指定任何依赖项。 So never use this option if your jar/plugin has any dependencies. 因此,如果您的jar /插件具有任何依赖性,请不要使用此选项。

References: 参考文献:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM