-2

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

  • What do you mean when you say "calculate"? – Eugene S Dec 19 '17 at 05:58
  • @EugeneS I mean to get a list of all dependence artifacts, including provided. I need to include them in ear of project. – Alexander Fedyukov Dec 19 '17 at 06:00
  • `mvn dependency:tree` will show all dependencies. Perhaps that can help you with what you need? – Eugene S Dec 19 '17 at 06:03
  • If you need to include them in the EAR, they are not provided. You are simply using the wrong scope here. You should discuss this with the author of the "best practices". – Henry Dec 19 '17 at 06:07
  • Of course not. I heed to get all provided artifacts too, as I pointed in my question. Customer made a mistake marking all own artifacts as provided, but it can't give to us archive, which will contains all of them. – Alexander Fedyukov Dec 19 '17 at 06:08
  • Unfortunately, author is not ready to discus this question with me. It suppose that it is "best practice". That is why I going to calculate them manually... Maybe maven can helps me with it? – Alexander Fedyukov Dec 19 '17 at 06:11
  • Does commentators can describe what is wrong with the question? – Alexander Fedyukov Dec 19 '17 at 06:21
  • If you say you need to include them into an EAR file this means you haven't understood the meaning of `provided` cause that means they will **NOT** be included into the EAR file...Apart from that `best practices` what does that mean? Only artifacts which should not be packaged into the EAR/WAR file should be marked with `provided` which has nothing todo with an architecture... – khmarbaise Dec 19 '17 at 06:28
  • You don't hear me. Author of those artifacts made a mistake: it marked own artifacts as PROVIDED, but forgot make an artifact\folder\archive with whole of them (to put it in shared folder of application server in future). That is why I need to make this artifact or folder or archive by myself. Is it clear or needs additional clarification? – Alexander Fedyukov Dec 19 '17 at 06:34
  • A dependency report should show all the needed artifacts. – Henry Dec 19 '17 at 07:05
  • And transitive provided too? – Alexander Fedyukov Dec 19 '17 at 07:06
  • That's what I suggested. – Eugene S Dec 19 '17 at 07:59
  • You can try to overwrite the scope in your ear module? Have you tried to do so? – khmarbaise Dec 19 '17 at 08:09
  • No, I can't: artifacts marked as provided is placed in transitive artifacts. Author of it don't understand why he must not to do so. – Alexander Fedyukov Dec 19 '17 at 08:11
  • You can (see my answer). You can overwrite the scope of transitive dependencies with dependencyManagement without changing any of the "external" artifacts. – J Fabian Meier Dec 19 '17 at 14:15
  • No, it does not work. – Alexander Fedyukov Jan 20 '18 at 14:22

2 Answers2

0

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.

-1
  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).
J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
  • And what about provided artifacts on the second level of dependence? I see I must prepare a sample to clarify my question. I'll do it later. – Alexander Fedyukov Dec 19 '17 at 13:11
  • The entries in dependencyManagement work on _all_ levels of transitive dependencies. To be more specific: You put the dependencyManagement entries for all incorrect transitive dependencies in _your own_ ear, and they will overwrite the versions/scopes of the transitive dependencies (to which you have no direct access). – J Fabian Meier Dec 19 '17 at 13:12
  • But how I will be knowing whole of them? – Alexander Fedyukov Dec 20 '17 at 05:35
  • You use dependency:list, extract all "provided" dependencies, then you have the whole list of (transitive and non-transitive) provided dependencies. – J Fabian Meier Dec 20 '17 at 07:26
  • Would you look at my example and comment\extend your answer? – Alexander Fedyukov Dec 22 '17 at 06:48