Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何计算整个工件列表,包括提供的_Java_Maven_Dependency Management - Fatal编程技术网

Java 如何计算整个工件列表,包括提供的

Java 如何计算整个工件列表,包括提供的,java,maven,dependency-management,Java,Maven,Dependency Management,在当前的项目中,大多数可传递的工件被标记为“已提供”(由于项目架构的一些“最佳实践”——我不能改变这种行为)。但我需要得到他们的全部名单才能使这个项目活跃起来 如何计算整个工件列表,包括提供的工件? 如何覆盖可传递工件的“提供”范围 好的。以下是我的案例示例: <!-- sample of my pom is so:--> <project> ..... <group>rd-service</group> <artifactId&g

在当前的项目中,大多数可传递的工件被标记为“已提供”(由于项目架构的一些“最佳实践”——我不能改变这种行为)。但我需要得到他们的全部名单才能使这个项目活跃起来

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

好的。以下是我的案例示例:

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

.....
研发服务

  • 使用
    dependency:list
    可以提供(可传递和不可传递)依赖项的完整列表,包括提供的
    依赖项
  • 要覆盖可传递依赖项的范围,可以使用
    。dependencyManagement中的条目覆盖可传递依赖项的版本和范围(因此请确保选择正确的版本)
  • 我找到了这样的解决方案,并做了一些改进(不错,但还需要一些改进)
    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
    

    并收到一份完整的(超过需要的)可传递依赖项的列表。

    你说“计算”是什么意思?@EugeneS我的意思是得到一份所有依赖项工件的列表,包括提供的。我需要将它们包含在项目ear中。
    mvn依赖项:tree
    将显示所有依赖项。也许这可以帮助你做你需要的事情?如果你需要把它们放在耳朵里,它们是不提供的。您只是使用了错误的范围。你应该和“最佳实践”的作者讨论这个问题。当然不是。正如我在问题中指出的那样,我也注意获取所有提供的工件。客户错误地将所有自己的工件标记为提供的工件,但它不能将包含所有工件的存档提供给我们。那么,在第二个依赖级别上提供的工件又如何呢?我知道我必须准备一个样品来澄清我的问题。我稍后再做。DependencyManager中的条目适用于所有级别的可传递依赖项。更具体地说:您将所有不正确的可传递依赖项的dependencyManagement条目放在自己的ear中,它们将覆盖可传递依赖项的版本/范围(您无法直接访问这些版本/范围)。但我如何知道它们的全部?您可以使用dependency:list,提取所有“提供的”依赖项,然后你就有了提供的依赖项的完整列表(可传递和不可传递)。你能看看我的例子并评论\扩展你的答案吗?
    cat shared-libs-all.mvn|grep -v 'rd-service'|sort|uniq>shared-libs-prepared.mvn