admin管理员组

文章数量:1125111

Unfortunately in our project, dependencies and plugins are managed by another team so I can not modify the pom file as I wish. So I like to use a maven plugin in my project. In my case it is the pitest tool for mutation testing. I run the tool via command line like this

mvn clean test-compile org.pitest:pitest-maven:mutationCoverage -DtargetClasses="some.source.File" -DtargetTests="some.source.FileTest"

The command runs and does some things until pitest-maven plugin stops with an error.

09:56:40 PIT >> WARNING : TestNG is on the classpath but the pitest TestNG plugin is not installed.
09:56:40 PIT >> INFO : Verbose logging is disabled. If you encounter a problem, please enable it before reporting an issue.
09:56:41 PIT >> INFO : Created 1 mutation test units in pre scan
09:56:41 PIT >> INFO : Sending 1 test classes to minion
09:56:41 PIT >> INFO : Sent tests to minion
09:56:41 PIT >> SEVERE : Pitest could not run any tests. Please check that you have installed the pitest plugin for your testing library (eg JUnit 5, TestNG). If your project uses JUnit 4 the plugin is automatically included, but a recent version of JUnit 4 must be on the classpath.

When doing the forbidden thing and adding the respective dependeny the above command runs without errors.

<dependency>
    <groupId>org.pitest</groupId>
    <artifactId>pitest-testng-plugin</artifactId>
    <version>1.0.0</version>
    <scope>test</scope>
</dependency>

What can I do to make the additional plugin available on the classpath such that the above command works? But without changing the pom file.

Unfortunately in our project, dependencies and plugins are managed by another team so I can not modify the pom file as I wish. So I like to use a maven plugin in my project. In my case it is the pitest tool for mutation testing. I run the tool via command line like this

mvn clean test-compile org.pitest:pitest-maven:mutationCoverage -DtargetClasses="some.source.File" -DtargetTests="some.source.FileTest"

The command runs and does some things until pitest-maven plugin stops with an error.

09:56:40 PIT >> WARNING : TestNG is on the classpath but the pitest TestNG plugin is not installed.
09:56:40 PIT >> INFO : Verbose logging is disabled. If you encounter a problem, please enable it before reporting an issue.
09:56:41 PIT >> INFO : Created 1 mutation test units in pre scan
09:56:41 PIT >> INFO : Sending 1 test classes to minion
09:56:41 PIT >> INFO : Sent tests to minion
09:56:41 PIT >> SEVERE : Pitest could not run any tests. Please check that you have installed the pitest plugin for your testing library (eg JUnit 5, TestNG). If your project uses JUnit 4 the plugin is automatically included, but a recent version of JUnit 4 must be on the classpath.

When doing the forbidden thing and adding the respective dependeny the above command runs without errors.

<dependency>
    <groupId>org.pitest</groupId>
    <artifactId>pitest-testng-plugin</artifactId>
    <version>1.0.0</version>
    <scope>test</scope>
</dependency>

What can I do to make the additional plugin available on the classpath such that the above command works? But without changing the pom file.

Share Improve this question asked 2 days ago FuryFartFuryFart 2,3944 gold badges29 silver badges48 bronze badges 4
  • dependency:build-classpath springs to mind. Run it manually after running that and adding the required dependencies to the classpath – g00se Commented 2 days ago
  • Going around the security team measures will get you fired. – user2023577 Commented 2 days ago
  • I do not care about their security measures or policies. I want to use the tools I deem usefull without need to argue with somebody. – FuryFart Commented 2 days ago
  • There is no information about what kind of project this is so a fair bit of looking in a crystal ball is required here. My thoughts go to creating your own pom outside of the project and then including "the project" as a dependency in it. In that pom you can do whatever you like. But how viable such a rebellious workaround would be fully depends on the type of project it is and how it is built up. – Gimby Commented 2 days ago
Add a comment  | 

1 Answer 1

Reset to default 1

First adding a dependency as part for pitest-maven is the wrong way because it's not a dependency of your project (neither a test-scoped). It is a dependency of the pitest-maven plugin which requires that dependency. The correct way to do that is like this:

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.pitest</groupId>
          <artifactId>pitest-maven</artifactId>
          <version>1.17.3</version>
          <dependencies>
            <dependency>
              <groupId>org.pitest</groupId>
              <artifactId>pitest-testng-plugin</artifactId>
              <version>1.0.0</version>
            </dependency>
          </dependencies>
        </plugin>
      </plugins>
    </pluginManagement>
    ...
  </build>

You can create the classpath by using maven-dependency-plugin:build-classpath which will represent exactly the classpath for your defined dependencies (from your pom.xml file).. but that would mean to do something outside Maven (a script or alike) which is the wrong way...

本文标签: javaHow to extend Maven classpath without modifying pomStack Overflow