How can I view transitive dependencies of a Maven pom.xml file?

On the CLI, use mvn dependency:tree (Here are some additional Usage notes) When running dependency:tree on multi-module maven project, use mvn compile dependency:tree instead1. Otherwise, the POM Editor in M2Eclipse (Maven integration for Eclipse) is very good, and it includes a hierarchical dependency view. 1If you don’t compile, you might get error Failed to execute … Read more

How to add “Maven Managed Dependencies” library in build path eclipse?

from the command line type: mvn eclipse:eclipse this will add all the dependencies you have in your pom.xml into eclipse… however, if you haven’t done any of this before you may need to do one other, one time only step. Close eclipse, then run the following command from the shell: mvn -Declipse.workspace=<eclipse workspace> eclipse:add-maven-repo sample: … Read more

How to add a dependency to a Spring Boot Jar in another project?

By default, Spring Boot repackages your JAR into an executable JAR, and it does that by putting all of your classes inside BOOT-INF/classes, and all of the dependent libraries inside BOOT-INF/lib. The consequence of creating this fat JAR is that you can no longer use it as a dependency for other projects. From Custom repackage … Read more

m2eclipse error

I had same problem with Eclipse 3.7.2 (Indigo) and maven 3.0.4. In my case, the problem was caused by missing maven-resources-plugin-2.4.3.jar in {user.home}\.m2\repository\org\apache\maven\plugins\maven-resources-plugin\2.4.3 folder. (no idea why maven didn’t update it) Solution: 1.) add dependency to pom.xml <dependency> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.4.3</version> </dependency> 2.) run mvn install from Eclipse or from command line 3.) refresh the … Read more

How can I skip tests in maven install goal, while running them in maven test goal?

It sounds like you didn’t understand the concept of the build life-cycle in Maven. If you run mvn install all life-cycle phases (including the install phase itself) run before the install phase. This means running the following phases: validate initialize generate-sources process-sources generate-resources process-resources compile process-classes generate-test-sources process-test-sources generate-test-resources process-test-resources test-compile process-test-classes test prepare-package package … Read more

JUnit 5 does not execute method annotated with BeforeEach

In my case the problem was that the @Test annotation was taken from wrong import. Originally it was imported from org.junit.Test. Once I have switched it to org.junit.jupiter.api.Test the problem was resolved. Wrong original code: import org.junit.Test; @BeforeEach …some code @Test …some code Correct fixed code: import org.junit.jupiter.api.Test; @BeforeEach …some code @Test …some code

Resource files not found from JUnit test cases

My mistake, the resource files WERE actually copied to target/test-classes. The problem seemed to be due to spaces in my project name, e.g. Project%20Name. I’m now loading the file as follows and it works: org.apache.commons.io.FileUtils.toFile(myClass().getResource(“resourceFile.txt”)‌​); Or, (taken from Java: how to get a File from an escaped URL?) this may be better (no dependency on … Read more

How to set spring active profiles with maven profiles

There is a more elegant way to switch between 2 maven+spring profiles simultaneously. First, add profiles to POM (pay attention – maven+spring profile is activated by single system variable): <profiles> <profile> <id>postgres</id> <activation> <activeByDefault>true</activeByDefault> <property> <name>spring.profiles.active</name> <value>postgres</value> </property> </activation> <dependencies> <dependency> <groupId>postgresql</groupId> <artifactId>postgresql</artifactId> <version>9.1-901.jdbc4</version> </dependency> </dependencies> </profile> <profile> <id>h2</id> <activation> <property> <name>spring.profiles.active</name> <value>h2</value> </property> </activation> … Read more