"No tests were found" when running individual test in Intellij with Spock and Spring Boot - spring-boot

Running whole test class works just fine. However when I try to click gutter icon next to the test method I get following error:
org.junit.platform.commons.JUnitException: TestEngine with ID
'junit-jupiter' failed to discover tests

Problem is related with newest changes in junit platform. Not sure what exactly changed, but following steps fixed tests for me:
Change junit platform version to 1.5.2 (this is the last one working):
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-commons</artifactId>
<version>1.5.2</version>
</dependency>
Exclude junit vintage engine from spring-boot-starter-test:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>

Related

RESOLVED - Spring Boot Starter Mail - failed to access class com.sun.activation.registries.LogSupport from class javax.activation.MimetypesFileTypeMap

I want to share the solution for above issue when using Spring Boot Starter Mail and attempt to create instance of MimeMessageHelper results in exception:
failed to access class com.sun.activation.registries.LogSupport from class javax.activation.MimetypesFileTypeMap
The issue is behind the jaxb-core dependency in version 4.0.0 which brings angus-activation library dependency. The library if loaded first doesn't have a public class of LogSupport.
The correct source of LogSupport is from com.sun.activation:jakarta.activation library.
Solution is to exclude the following in jaxb-core dependency:
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>4.0.0</version>
<exclusions>
<exclusion>
<groupId>org.eclipse.angus</groupId>
<artifactId>angus-activation</artifactId>
</exclusion>
</exclusions>
</dependency>
At the same time the following dependency should be available:
<dependency>
<groupId>com.sun.activation</groupId>
<artifactId>jakarta.activation</artifactId>
<version>2.0.1</version>
</dependency>

what's the difference between spring-boot-test vs spring-boot-starter-test?

I a project I am handling, I see these dependencies defined:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
But I can't understand why there are 2 artifacts for testing with Spring Boot, what is the difference between both of them? Maybe with the latter, I am also importing the former?
The spring-boot-starter-test is an aggregated "starter pack" for libraries using often together for testing in Spring applications.
As stated in the latest version reference documentation, the spring-boot-starter-test contains:
JUnit 5 (including the vintage engine for backward compatibility with JUnit 4)
Spring Test & Spring Boot Test - This is the spring-boot-test dependency)
AssertJ, Hamcrest, Mockito, JSONassert, and JsonPath.
You can remove the explicit definition of the spring-boot-test dependency.
From Spring Boot official reference:
Spring Boot provides a number of utilities and annotations to help when testing your application. Test support is provided by two modules: spring-boot-test contains core items, and spring-boot-test-autoconfigure supports auto-configuration for tests.
more details>>
Please have a look at the maven definitions. The contents of the packages are detailed there. spring-boot-starter-test seems to be a superset of spring-boot-test since spring-boot-starter-test has dependency for spring-boot-test.
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test/2.2.5.RELEASE
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-test/2.2.5.RELEASE

Spring Boot No Class found error though starter dependency has added classes in classpath

Despite having appropriate jars in classpath Spring Boot throws - java.lang.ClassNotFoundException: org.apache.camel.spring.spi.XmlCamelContextConfigurer
Any suggestions what is missing here.
I have added the respective starters in pom.xml as shown below:
<dependency>
<groupId>org.springframework.boot</groupId>[![enter image description here][1]][1]
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf</artifactId>
<version>2.19.3</version>
</dependency>
The project maven dependencies also shows the class availability, as in given image attachment.
the answer is here - https://stackoverflow.com/a/34271507/2885422 It all depends how maven loads the class. There are 2 version of camel-spring.jars available in classpath (2.20.1 and 2.19.3. Ref: my original post image)
And org.apache.camel.spring.spi.XmlCamelContextConfigurer class is available only in 2.20.1 jars. And maven by default looks in earlier one and once package found matching but no class found throws error (?)
And the reason I believe 2.19.3 get loaded is Apache-cxf jars is of 2.19.3. Unfortunately our project repository does not have apache-cxf starter jars.
https://stackoverflow.com/a/34271507/2885422
Solution: - I hope it may be helpful for future references
By adding options I could resolve the issue,by having exclusion clause added as given below. Thus I could load only required version jars.
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf</artifactId>
<version>2.19.3</version>
<exclusions>
<exclusion>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
</exclusion>
</exclusions>
</dependency>'

How to exclude dependency of wsdl4j in axis1.4 as it is affecting the application not to work by throwing InovcationTargetException

Caused by:
java.lang.IncompatibleClassChangeError: Class com.ibm.wsdl.DefinitionImpl does not implement the requested interface javax.wsdl.extensions.AttributeExtensible
The reason for axis-wsdl4j-1.5.1.jar getting downloaded when you try and build using axis:1.4 in your project is that it is defined within dependency for the artifact itself..
If you don't want to download axis-wsdl4j-1.5.1.jar, you can exclude it from your project by making following changes to your pom.xml -
<dependencies>
<dependency>
<groupId>axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
<exclusions>
<exclusion> <!-- declaring the exclusion here -->
<groupId>axis</groupId>
<artifactId>axis-wsdl4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--...other dependencies -->
<dependencies>

Onejar-maven-plugin to set the order of jar loading

I've been using the library apache-log4j-extras for logging. It contains class org.apache.log4j.Logger.
Now I had to reference some 3rd party library, that uses logback and has among its dependencies log4j-over-slf4j (jar). Unfortunately, latter jar also contains class org.apache.log4j.Logger.
Looks like the latter class is preferred by the onejar classloader...
I don't need logback and log4j-over-slf4j. Just want my org.apache.log4j.Logger from apache-log4j-extras back. What are my options with the Onejar-maven-plugin?
EDIT: It appeared to be an issue with Debug mode in IDEA, not with onejar. However the question is still relevant: how can I ensure that I load the requried class with Onejar?
EDIT2: E.g. in C# it could be easily resolved with "extern alias" feature.
why don't you just exclude it?
<dependency>
<groupId>my.naughty.thirdparty</groupId>
<artifactId>thirdparty-with-log4j-over-slf4j</artifactId>
<version>${thirdparty.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
Looks like (for Debug mode in IDEA) just switching depenencies order solved the issue.
How it was:
<dependency>
<groupId>my.naughty.thirdparty</groupId>
<artifactId>thirdparty-ref-log4j-over-slf4j</artifactId>
<version>0.50</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>apache-log4j-extras</artifactId>
<version>1.1</version>
</dependency>
Changed to:
<dependency>
<groupId>log4j</groupId>
<artifactId>apache-log4j-extras</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>my.naughty.thirdparty</groupId>
<artifactId>thirdparty-ref-log4j-over-slf4j</artifactId>
<version>0.50</version>
</dependency>
But surely I can't consider it as a robust solution, especially for Onejar.

Resources