In Maven, how output the classpath being used?

后端 未结 7 1300
庸人自扰
庸人自扰 2020-12-12 23:31

For my current purposes I have a Maven project which creates a war file, and I want to see what actual classpath it is using when creating the war.

相关标签:
7条回答
  • 2020-12-13 00:37

    As ecerulm noted in his comment to Janik's answer, you may want to specify the scope to dependency:build-classpath, as classpath output will differ for different scopes (by default test is used for some reason). I've ended up with a command like this:

    mvn -DincludeScope=compile dependency:build-classpath
    

    Within the POM, it could be used like this:

    <project>
      [...]
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.9</version>
            <executions>
              <execution>
                <id>build-classpath</id>
                <phase>generate-sources</phase>
                <goals>
                  <goal>build-classpath</goal>
                </goals>
                <configuration>
                  <includeScope>compile</includeScope>
                  <!-- Omit to print on console: -->
                  <outputFile>${project.build.directory}/compile-classpath.txt</outputFile>
                </configuration>
              </execution>
              <execution>
                <id>build-test-classpath</id>
                <phase>generate-test-sources</phase>
                <goals>
                  <goal>build-classpath</goal>
                </goals>
                <configuration>
                  <includeScope>test</includeScope>
                  <!-- Omit to print on console: -->
                  <outputFile>${project.build.directory}/test-classpath.txt</outputFile>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
      [...]
    </project>
    

    This will output 2 versions of classpath, one for main build and the other for tests.

    0 讨论(0)
提交回复
热议问题