【发布时间】:2016-09-16 17:35:48
【问题描述】:
我需要阅读 Java 中的插件配置。我已经使用 aether 库来获取运行时依赖项、编译时依赖项等。但是我可以使用 aether 来读取基于 pom 文件的插件配置吗?
类似的东西
<properties>
<servicePort>8080</servicePort>
<adminPort>8081</adminPort>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.company.group</groupId>
<artifactId>my-plugin</artifactId>
<version>0.1-SNAPSHOT</version>
<configuration>
<myConfig>
<somePropName>someProp</somePropName>
<portMappings>
<someProp>${servicePort}</someProp>
<someProp-admin>${adminPort}</someProp-admin>
</portMappings>
</myConfig>
</configuration>
</plugin>
</plugins>
</build>
我希望能够解决
some-Prop 8080
some-prop-admin 8081
从这个机制
目前我像这样获取编译关系依赖项
Dependency dependency = new Dependency(new DefaultArtifact(
coordinate), COMPILE);
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(dependency);
collectRequest.addRepository(this.aetherSession
.getRemoteRepository());
DependencyNode node = this.aetherSession
.getRepoSystem()
.collectDependencies(this.aetherSession.getRepoSession(),
collectRequest).getRoot();
DependencyRequest dependencyRequest = new DependencyRequest();
dependencyRequest.setRoot(node);
result = this.aetherSession
.getRepoSystem()
.resolveDependencies(this.aetherSession.getRepoSession(),
dependencyRequest).getArtifactResults();
FinalResult.addAll(result);
【问题讨论】:
-
你能发布你当前的代码来获取编译时依赖吗?您是在编写 Maven 插件还是外部应用程序?
-
这是一个 java 应用程序,我想使用 aether 从 pom 中读取插件配置