【问题标题】:Path pom.xml in local .m2 repo in plugin插件中本地 .m2 存储库中的路径 pom.xml
【发布时间】:2012-05-18 15:28:33
【问题描述】:

我尝试制作一些 Maven 插件。我需要在安装阶段之后获取工件和 pom.xml 的路径。我得到了这样的工件路径:

D:\Work\test\mvn\moduleFirst\target\first-1.0-SNAPSHOT.jar

和 pom.xml 路径是这样的:

D:\Work\test\mvn\moduleFirst\pom.xml

但是如果在 pom.xml 包中设置了“pom”,那么我会得到这样的工件路径:

C:\Users\user.m2\repository\com\test\mvn\1.0-SNAPSHOT\mvn-1.0-SNAPSHOT.pom

还有 pom.xml:

D:\Work\test\mvn\pom.xml

我想从 .m2 本地仓库获取所有路径。怎么可能?

我制作以下代码:

...
    /**
     * @parameter default-value="${project.file}"
     */
    private File pomFile;
...
    /**
     * @parameter default-value="${project.artifact}"
     */
    private Artifact artifact;
...
    public void execute() throws MojoExecutionException {
...
        getLog().info("POM file " + pomFile.getAbsolutePath());
        getLog().info("Artifact " + artifact.getFile().getAbsolutePath());
...
    }

【问题讨论】:

    标签: maven plugins artifacts


    【解决方案1】:

    我找到了解决办法。

    ...
        /**
         * @parameter expression="${localRepository}"
         * @required
         * @readonly
         */
        protected ArtifactRepository localRepository;
    ...
        protected String getLocalRepoFile(Artifact artifact) {
            File file = new File(localRepository.getBasedir(), localRepository.pathOf(artifact));
            return file.getAbsolutePath();
        }
    ...
        public void execute() throws MojoExecutionException {
    ...
    getLog().info("Artifact " + getLocalRepoFile(artifact));
    ...
        }
    

    感谢 maven-install-plugin :)

    【讨论】:

      猜你喜欢
      • 2017-04-04
      • 2017-12-20
      • 2014-07-07
      • 1970-01-01
      • 2016-09-03
      • 2018-02-06
      • 2019-12-04
      • 1970-01-01
      • 2015-11-22
      相关资源
      最近更新 更多