0

I created a JUnit extension in a maven plugin project and I want to use this plugin and the JUnit extension in another project, but I have no idea how can I export and import dependencies of the maven plugin and the JUnit extension.

I tried to import the plugin in other project like this

<plugins>
        ...
        <plugin>
            <groupId>com.project</groupId>
            <artifactId>project-maven-plugin</artifactId>
            <version>1.0-SNAPSHOT</version>
            <executions>
                <execution>             
                    <goals>
                        <goal>my-goal</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
   ...
</plugins>

But it is not working. Thank you for the help

Grasshopper
  • 1,749
  • 1
  • 14
  • 30
toum59
  • 1
  • Can you explain how/why you have create a JUnit (Jupiter) extension? – khmarbaise Jun 05 '20 at 13:38
  • I created in order to calculate the time to perform during the execution of each test method of another project that would use my maven plugin that contains this extension. A question that I really ask myself how to intercept the tests of this project in MyMojo class of the maven plugin to perform this calculation – toum59 Jun 05 '20 at 18:33
  • My JUnit extension is a class that impements theses interface `BeforeTestExecutionCallback, AfterTestExecutionCallback, AfterAllCallback` to redefine thoses method `beforeTestExecution` `AfterTestExecution` and `AfterAll` I tested them in my localy plugin with the annoation `@ExtendWith(MyExtention.class)` it work. – toum59 Jun 05 '20 at 18:44
  • But why have you create a Maven plugin. A JUnit Jupiter extensions can be defined in a simple dependency and can be added to the appropriate project and executed by surefire/failsafe plugin? Apart from that if you have added the dependencies of your extension in the plugin the project can not see them cause the classloaders are separated. – khmarbaise Jun 06 '20 at 09:07
  • the goal of the project exactly is to create a maven plugin which could be used in any other maven project to perform code coverage from unit test. The question that I also ask myself is how can I intercept the tests from the `MOJO` class of my maven plugin and cover them by cheicking a time before and after execution. – toum59 Jun 08 '20 at 08:11
  • You are mentioning code coverage. I'm not sure about your intention but you know about jacoco-maven-plugin etc. ? – khmarbaise Jun 08 '20 at 12:29
  • Yes I know jacoco, and the final goal of my project is to have something resembling jacoco, I am only at the beginning of the project – toum59 Jun 08 '20 at 14:25
  • JaCoCo only records the code coverage (via an agent) but does not execute tests nor provides any kind of extension as you would like to do. So you would like to create a thing like surefure and jacoco ..in one mojo which sounds like the wrong way (separation of concern).. apart from accessing the tests/providing an extension which will not really based on the separation of the classloaders (not to speak about modules)... – khmarbaise Jun 08 '20 at 16:26

0 Answers0