How to specify test directory in Maven pom.xml [duplicate] - maven

This question already has an answer here:
Running groovy tests with Maven
(1 answer)
Closed 7 years ago.
Maven handles java unit tests well by defaulting to:
src/test/java
We're writing quite a few Groovy unit tests right now, and I'd like to find a way in Maven to specify a folder such as:
src/test/groovy
as a test folder. This would help us to import a Maven project into, say, IntelliJ, without additional setup.
Someone mentioned this was possible, but I wasn't able to find a way searching the Maven docs, or SO. Does anyone know how to mark the directory in the pom?
Thank you
Update: I am not asking how to run the tests in Maven! The tests are already running fine. I'm asking how to mark the directories as test directories in Maven.

As described at http://maven.apache.org/ref/3.3.3//maven-model/maven.html#class_build the build section of the pom.xml has an entry to specify the test folder.

Related

How to execute all test case in the “spring-boot” project with gradle?

spring-boot migrated from maven to gradle since 2.3.0.M1, so the question is tagged with gradle. link
What I want to do?
We known, spring-boot-dependencies project is managing lots of jar's version and works well, that's so great! We plan to use spring-boot-dependencies as a basic to manage jar's version in my company. sometimes we need to upgrade some of the jar in spring-boot-dependencies because of vulnerabilities, and this may cause version mismatch between jars.
I have noticed that, there is about 10*000 tests case in springboot project:
So I'd like to modify some jar's version in the spring-boot-dependencies project, and then run all test of spring-boot projects, to help me analyse is there any version mismatch。
What I did?
clone the latest code from github:https://github.com/spring-projects/spring-boot.git
run .\gradlew.bat build(work on windows) in the spring-boot project root directory.
it seems only a few tests get executed:
So, my question is how can I execute all test case in spring-boot project?
Any suggestions would be greatly appreciated!
the path buildSrc/ is for the gradle custom plugin code. You are therefore looking at the build tool test results.
your main code results will be under build/reports/... folder (of each module)

Maven - Jenkins issue

There are couple of issues I am facing in Jenkins integration . I run the scripts from local Eclipse and it works perfectly fine with Selenium Grid. I am trying to setup this whole thing in Jenkins and facing the following issues
1. cannot find symbol - Seeing this issue in Jenkins and searched about this in Stack Overflow . Verified the JDK version and my pom.xml version matches with the one installed in Jenkins.
2.I have three packages- One has the framework , second one has the main method and the third one has the code related to the application i am testing. I am converting my framework to a jar and uploading the entire thing to GIT . When i build the project jar using Maven install , its not including the framework jar which is causing the issue . I tried a lot of things suggested in Stack Overflow and it did not work. I am quite new to this kind of Maven stuff
3. I am not even able to run the scripts with the help of the runnable jar in my local because of issue# 2
Some of these have already been posted but i tried out those things and did not work for me or I might be missing something
In Maven you have a file called settings.xml which contains URL of the location from where you want to fetch all your dependencies like here JAR files in your case from GIT. It works from your eclipse because maven looks for dependencies in your .m2 folder which are there when you run it from eclipse. But, in order to build it from anywhere else you need to specify that URL in maven's settings.xml

maven provided dependency will cause NoClassDefFoundError in intellij?

IntelliJ doesn't seem to put the provided dependency on the classpath when I run it, however I can do this successfully in Eclipse.
As it would be a lot more convenient for me, how can I do this in IntelliJ?
I'm having the same problem. Intellij does not include provided dependencies in classpath. See this source. The best solution I found is to run it as maven app, using the exec:java goal. For example:
exec:java -Dexec.classpathScope=compile -Dexec.mainClass=com.splout.db.integration.NShardEnsemble -Dexec.args=4
Better solutions are welcome.
Does it work in Maven via command line? The behaviour seems correct. Eclipse used to handle classpath badly, so I guess it still does.
There is a difference if you run something in Test source root or Source root, since the scope provided is only available on the compilation and test classpath.
If you run a test, or a main method in Test source root, then it can use provided dependencies, but if you try to execute something (via IntelliJ, or exec-maven-plugin) in Source root, then it will fail on ClassNotFoundException.
IntelliJ now has an option to Include dependencies with provided scope in the Run Configuration:
Any library marked as scope - provided means that the library (as the name suggests) is supposed to be provided by the JDK or the container (e.g. tomcat) at runtime.
this answer is based on #Meo's answer.
ALT + Enter to create a unit test:
then run it :

How can I build a jar (with all it's dependencies) in maven? [duplicate]

This question already has answers here:
How can I create an executable/runnable JAR with dependencies using Maven?
(33 answers)
Closed 7 years ago.
I have a custom appliction, build in maven, with dependencies (more custom modules, and some other things like spring, apache commons and log4j).
How can I build an executable jar containing my application and all of it's dependencies? (I.e. what do I need to put in my pom.xml)
I am aware that it will be several megabytes in size, but I am looking for simplicity in building and executing my application.
And I would like to build via standard mvn clean install command.
Check out maven shade plugin. https://maven.apache.org/plugins/maven-shade-plugin/

Can we use maven surefire plugin to execute testcases present in the source directory

The Java project I am working on is a list of testcases written in Java for testing C++ code. So I want to run the testcases from the src directory in the test phase of the maven lifecycle. How do I configure the maven surefire plugin to achieve this.
Since it is Java based tests that presumably will not be part of the production code, I suggest that you follow Maven's standard directory layout and move the tests to the src/test/java directory as usual (otherwise, the tests will be part of the binary file if someone executes mvn package).

Resources