gpt4 book ai didi

java - 如何使用 API 3.1.1 在 Maven 插件中使用 Aether (eclipse)?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:25:48 24 4
gpt4 key购买 nike

我正在使用 API v3.1.1 开发一个新的 Maven 插件,因为我需要升级到 Maven 3.1.1,并且需要 Aether 方式来处理工件存储库,以及检索工件版本的完整列表等。我正在使用 Eclipse Aether (0.9.0.M4),不是 Sonatype Aether。

我已经通读了 http://wiki.eclipse.org/Aether并尝试了演示 http://git.eclipse.org/c/aether/aether-demo.git/tree/ , 但我无法理解为什么以下 within AbstractMojo 的子类不起作用。

两者都是 RepositorySystem repoSystem , RepositorySystemSession repoSession , List<RemoteRepository> projectRepos , 和 List<RemoteRepository> pluginReposnull .

我也尝试过使用 @Component注入(inject)具有相同结果的那些。

为了将这些对象注入(inject) mojo,我是否遗漏了什么?

import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.RemoteRepository;
...

public MyMojo extends AbstractMojo
{

/**
* The entry point to Aether, i.e. the component doing all the work.
*
* @component
*/
private RepositorySystem repoSystem;

/**
* The current repository/network configuration of Maven.
*
* @parameter default-value="${repositorySystemSession}"
* @readonly
*/
private RepositorySystemSession repoSession;

/**
* The project's remote repositories to use for the resolution of project dependencies.
*
* @parameter default-value="${project.remoteProjectRepositories}"
* @readonly
*/
private List<RemoteRepository> projectRepos;

/**
* The project's remote repositories to use for the resolution of plugins and their dependencies.
*
* @parameter default-value="${project.remotePluginRepositories}"
* @readonly
*/
private List<RemoteRepository> pluginRepos;

// Your other mojo parameters and code here
...
}

最佳答案

最后,它对我有用,我认为它之前不起作用的原因是我的 pom.xml 中有太多的依赖关系,事情没有得到正确的解决。

这是我使用的完整 pom.xml,以便原始帖子中的代码正常工作。其余代码来自 aether-demo,原始帖子中也提供了链接

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>aether.example</groupId>
<artifactId>my-aether-plugin</artifactId>
<version>1.0.1-SNAPSHOT</version>
<packaging>maven-plugin</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mavenVersion>3.1.1</mavenVersion>
<aetherVersion>0.9.0.M4</aetherVersion>
<mavenPluginVersion>3.2</mavenPluginVersion>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>${mavenPluginVersion}</version>
<configuration>
<goalPrefix>my-aether</goalPrefix>
<!-- see http://jira.codehaus.org/browse/MNG-5346 -->
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
<executions>
<execution>
<id>mojo-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
<execution>
<id>help-goal</id>
<goals>
<goal>helpmojo</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${mavenVersion}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.plexus</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-api</artifactId>
<version>${aetherVersion}</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-util</artifactId>
<version>${aetherVersion}</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

关于java - 如何使用 API 3.1.1 在 Maven 插件中使用 Aether (eclipse)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21612945/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com