Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
244 views
in Technique[技术] by (71.8m points)

java - How I can calculate whole list of artifacts, including provided

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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	%s	%s	%s	%s
", 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...