【问题标题】:How I can calculate whole list of artifacts, including provided我如何计算整个工件列表,包括提供的
【发布时间】:2018-06-01 12:30:12
【问题描述】:

在当前项目中,大多数传递工件都标记为“已提供”(由于项目架构的一些“最佳实践” - 我无法更改此行为)。但是我需要获得他们的完整列表才能使项目活跃起来。

我如何计算整个工件列表,包括提供的? 如何覆盖传递工件的“提供”范围?

好的。我的案例有一个样本:

<!-- sample of my pom is so:-->

<project>
.....
  <group>rd-service</group>
  <artifactId>rd-service</artifactId>

.....
  <dependencies>
.....
    <!--link to the problem artifact -->
    <dependency>
        <groupId>third-party-lib-group</groupId>
        <artifactId>third-party-lib-artifact</artifactId>
        <scope>compile</scope>
    </dependency>
  </dependencies>
</project>

     <!--problem artifact looks like so -->
<project>
.....
   <group>third-party-lib-group</group>
   <artifactId>third-party-lib-artifact</artifactId>

.....
  <dependencies>
.....
    <!--How I can calculate automatically whole dependencies
   which looks like this and its transitive 
   dependencies too? 
   Author of spring-context-customized can't do it by himself. -->
    <dependency>
        <groupId>org.springframework.fork</groupId>
        <artifactId>spring-context-customized</artifactId>
        <scope>provided</scope>
    </dependency>
  </dependencies>
</project>

再看问题here

【问题讨论】:

  • 你说“计算”是什么意思?
  • @EugeneS 我的意思是获取所有依赖项的列表,包括提供的。我需要将它们包含在项目中。
  • mvn dependency:tree 将显示所有依赖项。也许这可以帮助您满足您的需求?
  • 如果您需要将它们包含在 EAR 中,则不提供它们。您只是在这里使用了错误的范围。您应该与“最佳实践”的作者讨论这个问题。
  • 当然不是。正如我在问题中指出的那样,我也注意获取所有提供的工件。客户将所有自己的工件标记为已提供时出错,但它无法将包含所有工件的存档提供给我们。

标签: java maven dependency-management


【解决方案1】:
  1. 使用dependency:list 可以为您提供包括provided 在内的(传递和非传递)依赖项的完整列表。
  2. 要覆盖传递依赖的范围,可以使用&lt;dependencyManagement&gt;。 dependencyManagement 中的条目会覆盖传递依赖项的版本和范围(因此请确保选择正确的版本)。

【讨论】:

  • 那么在第二级依赖中提供的工件呢?我知道我必须准备一个样本来澄清我的问题。我稍后再做。
  • dependencyManagement 中的条目适用于所有层的传递依赖。更具体地说:您将所有不正确的传递依赖项的dependencyManagement 条目放在您自己的 耳中,它们将覆盖传递依赖项的版本/范围(您无法直接访问)。
  • 但是我怎么才能知道它们的全部呢?
  • 您使用依赖项:列表,提取所有“提供”依赖项,然后您将获得(传递和非传递)提供的依赖项的整个列表。
  • 你会看我的例子并评论\扩展你的答案吗?
【解决方案2】:

我找到了这样的解决方案https://stackoverflow.com/a/22411538/1458394 并做了一些改进(还不错,但还需要一些改进)deps-resolver.sh

    #!/bin/sh
if [ "$#" -ne 5 ]; then
  echo "Usage: $0 <groupId> <artifactId> <version> <scope> <type>"
  exit
fi

echo $1 $2 $3 $4 

echo "<dependency><groupId>$1</groupId><artifactId>$2</artifactId><version>$3</version><scope>compile</scope><type>$5</type></dependency>">>shared-libs-all.mvn

POM_DIR="`echo "$1" | tr . /`/$2/$3"
POM_PATH="$POM_DIR/$2-$3.pom"

excludeClassifiers=client
excludeGroupIds=org.apache.openjpa,javax.jms,javax.ejb,javax.servlet,com.ibm.ws,org.hibernate.javax.persistence,org.jboss.spec.javax.transaction,javax.mail,javax.activation,taglibs
excludeArtifactIds=
excludeScope=''

#echo -DexcludeClassifiers="$excludeClassifiers" -DexcludeGroupIds="$excludeGroupIds" -DexcludeArtifactIds="$excludeArtifactIds" -DexcludeScope="$excludeScope"

#mkdir -p "$HOME/.m2/repository/$POM_DIR"
#wget -q -O "$HOME/.m2/repository/$POM_PATH" "http://repo.maven.apache.org/maven2/$POM_PATH"
mvn -f "$HOME/.m2/repository/$POM_PATH" dependency:resolve -DexcludeClassifiers="$excludeClassifiers" -DexcludeGroupIds="$excludeGroupIds" -DexcludeArtifactIds="$excludeArtifactIds" -DexcludeScope="$excludeScope" -o -DincludeParents=true|egrep $4|awk '{split($0,a,"    ");  print(a[2]);}'|awk '{split($0,a,":"); printf("./deps-resolver.sh %s\t%s\t%s\t%s\t%s\n", a[1],a[2],a[4],"provided",a[3]);}'|sh

然后做

cat shared-libs-all.mvn|grep -v 'rd-service'|sort|uniq>shared-libs-prepared.mvn

并接收一个完整的(以及超出需要的)传递依赖项的列表。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-23
    • 1970-01-01
    • 2021-03-16
    • 2019-08-04
    • 1970-01-01
    • 2022-06-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多