Skip to content

Instantly share code, notes, and snippets.

@umjammer
Created September 7, 2024 20:26
Show Gist options
  • Select an option

  • Save umjammer/0a56f0a3a6e7f7ebec641661fd6bb36d to your computer and use it in GitHub Desktop.

Select an option

Save umjammer/0a56f0a3a6e7f7ebec641661fd6bb36d to your computer and use it in GitHub Desktop.
[java] print all dependency jars in pom.xml using delimiter ':'
#!/bin/bash
if [ ! -e pom.xml ]; then
echo no pom.xml
exit 1
fi
result=""
while read line; do
if [ -n "$result" ]; then
result="${result}:"
fi
result="${result}${line}"
done < <(mvn -P classpath validate | grep maven.dependency | grep "\.jar$" | awk -F= '{print $2}')
echo $result
@umjammer

umjammer commented Sep 7, 2024

Copy link
Copy Markdown
Author

before running shell script above, add below to your pom.xml profile section

    <profile>
      <id>classpath</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.6</version> <!-- must be 1.6 -->
            <executions>
              <execution>
                <phase>validate</phase>
                <configuration>
                  <target>
                    <echoproperties prefix="maven.dependency" />
                  </target>
                </configuration>
                <goals>
                  <goal>run</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment