Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A required class was missing while executing org.assertj:assertj-assertions-generator-maven-plugin:2.1.0:generate-assertions: org.junit.rules.TestRule #57

Open
akuma8 opened this issue Feb 20, 2019 · 3 comments

Comments

@akuma8
Copy link

akuma8 commented Feb 20, 2019

I am facing this issue when migrating my application from JDK8 to JDK11.

[ERROR] Failed to execute goal org.assertj:assertj-assertions-generator-maven-plugin:2.1.0:generate-assertions (default) on project mws-inbound: Execution default of goal org.assertj:assertj-assertions-generator-maven-plugin:2.1.0:generate-assertions failed: A required class was missing while executing org.assertj:assertj-assertions-generator-maven-plugin:2.1.0:generate-assertions: org.junit.rules.TestRule
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>org.assertj:assertj-assertions-generator-maven-plugin:2.1.0
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/C:/Users/admin/.m2/repository/org/assertj/assertj-assertions-generator-maven-plugin/2.1.0/assertj-assertions-generator-maven-plugin-2.1.0.jar
[ERROR] urls[1] = file:/C:/Users/admin/.m2/repository/org/assertj/assertj-assertions-generator/2.1.0/assertj-assertions-generator-2.1.0.jar
[ERROR] urls[2] = file:/C:/Users/admin/.m2/repository/org/apache/commons/commons-lang3/3.5/commons-lang3-3.5.jar
[ERROR] urls[3] = file:/C:/Users/admin/.m2/repository/commons-cli/commons-cli/1.2/commons-cli-1.2.jar
[ERROR] urls[4] = file:/C:/Users/admin/.m2/repository/com/google/guava/guava/20.0/guava-20.0.jar
[ERROR] urls[5] = file:/C:/Users/admin/.m2/repository/ch/qos/logback/logback-classic/1.0.13/logback-classic-1.0.13.jar
[ERROR] urls[6] = file:/C:/Users/admin/.m2/repository/ch/qos/logback/logback-core/1.0.13/logback-core-1.0.13.jar
[ERROR] urls[7] = file:/C:/Users/admin/.m2/repository/org/assertj/assertj-core/2.9.1/assertj-core-2.9.1.jar
[ERROR] urls[8] = file:/C:/Users/admin/.m2/repository/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar
[ERROR] urls[9] = file:/C:/Users/admin/.m2/repository/commons-io/commons-io/2.5/commons-io-2.5.jar
[ERROR] urls[10] = file:/C:/Users/admin/.m2/repository/backport-util-concurrent/backport-util-concurrent/3.1/backport-util-concurrent-3.1.jar
[ERROR] urls[11] = file:/C:/Users/admin/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.11/plexus-interpolation-1.11.jar
[ERROR] urls[12] = file:/C:/Users/admin/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.15/plexus-utils-1.5.15.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[maven.api, parent: null]]
[ERROR] 

Any idea?

@shaundsmith
Copy link

We've hit the same problem with assertj-assertions-generator-maven-plugin:2.2.0.

We found that a mvn clean test causes the assertions to be created correctly, but any subsequent mvn test will fail with the above issue.

We're using JDK11/Maven 3.6.0/JUnit 5 in our tech stack.
A workaround for our particular case is to add an explicit dependency on JUnit 4 in the plugin's declaration:

<plugin>
    <groupId>org.assertj</groupId>
    <artifactId>assertj-assertions-generator-maven-plugin</artifactId>
    <version>2.2.0</version>
    <executions>
        <execution>
            <goals>
                <goal>generate-assertions</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        ....
    </configuration>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13</version>
        </dependency>
    </dependencies>
</plugin>

@pkrajanand
Copy link

I run into the same error when running mvn -Dit.test='testClassName.testMethodNameWithSpaces' verify.

My running environment is

Picked up _JAVA_OPTIONS: -Duser.home=/home
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/share/maven
Java version: 1.8.0_252, vendor: Azul Systems, Inc., runtime: /usr/lib/jvm/zulu-8-amd64/jre
Default locale: en_US, platform encoding: ANSI_X3.4-1968
OS name: "linux", version: "4.19.76-linuxkit", arch: "amd64", family: "unix"

Any suggestions?

Of course, I didn't get the same when I run the whole test suite through mvn clean install

@bedla
Copy link

bedla commented Sep 26, 2020

This is very interesting class loader problem, so I have investigated it more deeply and created repo to reproduce https://github.com/bedla/maven-assertj-generator-test-error

There are two workarounds described.

First to add JUnit4 to plugin dependencies:

            <plugin>
                <groupId>org.assertj</groupId>
                <artifactId>assertj-assertions-generator-maven-plugin</artifactId>
                <version>2.2.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate-assertions</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <generateJUnitSoftAssertions>true</generateJUnitSoftAssertions>
                    <packages>
                        <param>cz.bedla.dto</param>
                    </packages>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>junit</groupId>
                        <artifactId>junit</artifactId>
                        <version>4.12</version>
                    </dependency>
                </dependencies>
            </plugin>

And second to disable JUnit soft assertion generation:

            <plugin>
                <groupId>org.assertj</groupId>
                <artifactId>assertj-assertions-generator-maven-plugin</artifactId>
                <version>2.2.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate-assertions</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <generateJUnitSoftAssertions>false</generateJUnitSoftAssertions>
                    <packages>
                        <param>cz.bedla.dto</param>
                    </packages>
                </configuration>
            </plugin>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants