- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我的问题与此密切相关 one
但我无法让它工作。希望更多人关注它会有所帮助
我的环境
Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 08:22:22-0700)
Maven home: /usr/local/maven
Java version: 1.8.0_40, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.11.3", arch: "x86_64", family: "mac"
我使用的是 maven 3.1,所以我使用的是新的 eclipse.aether,而不是 sonatype.aether。
我的插件
package aether.example;
import java.util.List;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.RemoteRepository;
@Mojo(name="test")
public class TestMojo 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;
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
System.out.println("TestMojo");
System.out.println("Session: " + repoSession);
System.out.println("Repos: " + projectRepos);
System.out.println("repoSys: " + repoSystem);
}
}
我的 pom.xml
<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>1.1.0</aetherVersion>
<mavenPluginVersion>3.2</mavenPluginVersion>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<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>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
我的安装方式
mvn clean install
我的运行方式
mvn aether.example:my-aether-plugin:test
我的输出
TestMojo
Session: null
Repos: null
repoSys: null
这是怎么回事?
最佳答案
我想出了我的问题。出于某种原因,评论部分中的注释不起作用,即使代码是直接从文档中复制的。
代替
/**
* 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;
我把它换成了
@Component
private RepositorySystem repoSystem;
/**
* The current repository/network configuration of Maven.
*/
@Parameter(defaultValue = "${repositorySystemSession}")
private RepositorySystemSession repoSession;
/**
* The project's remote repositories to use for the resolution of project dependencies.
*/
@Parameter(defaultValue = "${project.remoteProjectRepositories}")
private List<RemoteRepository> projectRepos;
关于java - 使用Maven3.1,不注入(inject)RepositorySystemSession和RepositorySystem,保持null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35189569/
我正在尝试使用 Artifact maven-plugin-testing-harness:3.3.0 对 Maven 插件的 Mojo 运行单元测试,并具有以下依赖项。但是当我尝试“lookupEm
我一直在 maven-dependency-plugin 中看到标签的 NoSuchElementException。我已尝试将 aether-spi、aether-api 和 aether-util
这个问题在这里已经有了答案: Android Studio : Error injecting while Appengine backend generation (1 个回答) 关闭 8 年前。
也许这将是一项比我原先想象的更大的任务,但无论如何,我正在尝试从文件加载 MavenProject,然后解析其依赖项。我有两个位的代码,但缺少一些我需要的对象引用;具体来说,我需要获取 Reposit
我正在尝试将 maven-plugin-testing-harness 2.1 版与以下测试用例一起使用: public class FooTest extends AbstractMojoTestC
我刚刚开始使用 Drools 并尝试将其与我的 Spark Streaming 工作集成。我将 Drools 6.3.0.Final 与 kie-ci 一起使用,这样我就可以从 Spark 作业中远程
我是一名优秀的程序员,十分优秀!