List of dependency jar files in Maven

后端 未结 9 2275
我在风中等你
我在风中等你 2020-12-04 09:50

Using Maven 2, is there a way I can list out the jar dependencies as just the file names?

mvn dependency:build-classpath 

can list the jar

9条回答
  •  猫巷女王i
    2020-12-04 10:13

    As best as I can tell, you can't get exactly that output, with the commas and no spaces. Both via the command line and via the pom.xml file, the maven-dependency-plugin or the CLI freaks out if you specify spaces or the '' (empty string) as a substitute with either pathSeparator or fileSeparator. So, you may be forced to reach something of a compromise. You can

        mvn dependency:build-classpath -Dmdep.pathSeparator=":" -Dmdep.prefix='' -Dmdep.fileSeparator=":" -Dmdep.outputFile=classpath
    

    However, that should get you a full list, separated by '::' instead of just ',', but it works. If you run:

        mvn dependency:build-classpath -Dmdep.pathSeparator="@REPLACEWITHCOMMA" -Dmdep.prefix='' -Dmdep.fileSeparator="@" -Dmdep.outputFile=classpath
    

    and attach this to the generate-resources phase and filter that resource later by setting the correct property in the process-resources phase of the lifecycle, you should be able to get just the comma.

    You can see the full list of options at: http://maven.apache.org/plugins/maven-dependency-plugin/build-classpath-mojo.html

提交回复
热议问题