在maven插件中获取完整依赖项名称

时间:2015-07-07 10:07:05

标签: java maven maven-plugin

如何在maven插件中获得完整的依赖项名称? 现在我正在使用这个功能:

private String getDependencyFilename(final Dependency toBeResolved) {
    return toBeResolved.getArtifactId() + "-" + toBeResolved.getVersion() + "." + toBeResolved.getType();
}

我想知道是否有任何内置函数可以做到这一点。

这里描述了依赖类:https://maven.apache.org/ref/3.3.1/maven-model/apidocs/org/apache/maven/model/Dependency.html

编辑: 我现在没有找到好的答案,所以我正在使用这段代码,也许对某人有用:

/**
 * Returns full name of dependency file format: artifactId-version-classifier.type , e.g.: simple-jboss-plugin-1.22-prod.jar
 * @param  dependency from which name will be extracted
 * @return the name of dependency file
 */
public static String getDependencyFilename(final Dependency dependency) {
    return dependency.getArtifactId() + "-" + dependency.getVersion()
            + resolveClassifier(dependency.getClassifier()) + "." + dependency.getType();
}

/**
 * Returns classifier with appended '-', or empty string if there is no classifier or if classifier is empty
 * @param classifier
 * @return resolved classifier string
 */
private static String resolveClassifier(final String classifier) {
    return Strings.isNullOrEmpty(classifier) ? "" : "-" + classifier;
}

0 个答案:

没有答案