How I can calculate whole list of artifacts, including provided

末鹿安然 提交于 2019-12-14 03:34:46

问题


In current project most of transitive artifacts are marked as "provided" (due to some of "best practices" of project architecture - I can't change this behavior). But I need to get whole list of their to make project alive.

How I can calculate whole list of artifacts, including provided? How to override "provided" scope of transitive artifact?

Okay. There is an sample of my case:

<!-- 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>

Another look on the problem here


回答1:


I found such solution https://stackoverflow.com/a/22411538/1458394 and made some improvements (not bad, but it needs some another improvements) 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

And then do

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

and receive a list of whole (and more than needed) transitive dependencies.




回答2:


  1. Using dependency:list gives you the whole list of (transitive and non-transitive) dependencies including the provided ones.
  2. To overwrite the scope of transitive dependencies, you can use <dependencyManagement>. Entries in the dependencyManagement overwrite the version and scope of the transitive dependencies (so make sure you pick the right version).


来源:https://stackoverflow.com/questions/47880746/how-i-can-calculate-whole-list-of-artifacts-including-provided

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!