私はMavenプラグインを開発しており、MavenProject
オブジェクトを使用して依存関係にアクセスしてproject.getDependencyArtifacts()
います.
すべての非ランタイム jar をフィルタリングする方法はありますか? スコープを取得して比較するscope.equals("runtime")
と、コンパイルやその他の重要な依存関係が破棄されます。
私はMavenプラグインを開発しており、MavenProject
オブジェクトを使用して依存関係にアクセスしてproject.getDependencyArtifacts()
います.
すべての非ランタイム jar をフィルタリングする方法はありますか? スコープを取得して比較するscope.equals("runtime")
と、コンパイルやその他の重要な依存関係が破棄されます。
これに対する既存の方法も見つからなかったため、次のロジックを使用しています。これは、必要な依存関係を xml ファイルに追加してアーカイブに含める、カスタマイズされた ear を構築するプラグインです。推移的な依存関係にも興味があるので、getArtifacts
代わりに使用しています。getDependencyArtifacts
Collection<Artifact> dependencies = new ArrayList<Artifact>();
dependencies.addAll(project.getArtifacts());
for (Iterator<Artifact> it=dependencies.iterator(); it.hasNext(); ) {
Artifact dependency = it.next();
String scope = dependency.getScope();
String type = dependency.getType();
if (dependency.isOptional() || !"jar".equals(type) || "provided".equals(scope) || "test".equals(scope) || "system".equals(scope)) {
getLog().debug("Pruning dependency " + dependency);
it.remove();
}
}