What is the easiest way of setting up a gradle configuration so that I can run tests for only one or two submodules in a multimodule project?
The reason I don't need to test all of them is because they reside in their own repositories and get tested when those are changed. It really increases the turnaround-time to have TeamCity run a shitload of tests that I know will pass.
My initial thought was to set up a task in the top-level build.gradle that has dummy implementations in the modules that don't need to run the tests and performs connectedCheck for the android submodule and runs the tests for the java ones, but I havn't gotten that to work yet. I looked at the gradle documentation for multi-project builds (http://www.gradle.org/docs/current/userguide/multi_project_builds.html) but couldn't figure out how to call the clean and build commands from inside a Closure.
Help? :)
Related
I have a maven project with a couple of child modules. One is a new maven plugin. Another one is a test module where I want to run my newly developed plugin to ensure that it works fine.
In the test module I do a normal reference to my plugin: build > plugins > plugin > <definition of my plugin>. And then if I executed mvn clean test it works fine. The plugin is being compiled and later, in the next module it is executed.
But there are a couple of problems with this setup:
When I do mvn clean execution fails with plugin cannot be resolved as the second module does not have even compiled version of the plugin.
In IDE (Intellij IDEA) reimport of maven modules fails with the same problem.
I do not want to do mvn install to have it locally so the dependencies are resolved as I do changes quite frequently and do not want to reinstall it every time.
I do not want to write integration tests instead of running the plugin directly as I want a realistic test and moreover, the plugin setup is quite tricky and would be hard to replicate that in a test.
I thought that I could use systemPath to reference the plugin but I am not sure if that will work and how to set it up.
I have a java spring-boot project with maven as my build framework.
I do have several plugins configured that do annotation processing during the compilation phase (mapstruct, lombok, etc).
One of those plugins has a bug and doesn't work well within IntelliJ.
That causes my build to fail if I simply try to build a module (all of my annotation processors are properly configured as it worked fine in the past, it's the upgrade to jdk14 caused an avalanche effect, spring-boot along with a bunch of libs and plugins had to be upgraded).
I figured that there is an option to delegate all build/run actions to Maven. And it works pretty well.
Except that I used to select a SpringBootTest and run it, now, when I do that it initiates a maven sequence, that triggers clean and install goals.
It doesn't make sense in my case as I have plenty of other modules that are hooked to compile goals: Checktyle, PMD, SpotBugs, Surefire, etc.
I would like the execution of a test to compile source code and run that particular test class/case.
Is that doable?
I am working on understanding Maven and I'm learning about building your Java app with it.
So when I do a :
maven package
It does build my jar as expected but I see in the output console that Maven does build tests (it always say that the test a run and there are no failure).
I researched on the web about that and learned that Maven use a plugin called Maven Surefire. But I can't understand what does that plugin do to my code, what does the tests "means" ? What does the tests do with my code and how it works behind the console ?
The Maven surefire plugin runs the tests you have written. These are usually in the src/test/java folder. If you have none, the plugin does nothing.
Is this only one question? :D
So. Different things are going on.
You create an application with Java. To test the single components / packages / classes that you create most people use JUnit or TestNg. You usually have dedicated test classes that verify your production code behaves as intended without you clicking through all the things on every change.
When you now use maven to run your build the pom.xml file defines a packaging - in your case "jar" since you create a jar file. The packaging defines what set of default plugins run in the defined maven phases. You probably recognize package here. Maven executes all phases up to package and the registered / configured plugins.
To execute those tests maven provides the surefire plugin which supports running JUnit or TestNg tests. If you follow the directory conventions your tests reside in src/test/java and the surefire includes naming convention maven will execute those tests in every build (as this is the best practice). If you also want to write integration tests then there is the failsafe plugin. That plugin is not enabled by default and runs in different maven phases.
So the tests just run your production code - in fact they just do what you implement in the tests. They don't alter it in any way.
The maven introduction documentation has step by step explanations: Maven in 5 Minutes and the Getting Started Guide.
Starting from scratch this is probably a lot. So don't rush this. The build setup and test setup are very important things to have.
I have two projects in java. ProjectA is published into artifactory, and projectAB has jar of projectA as a dependency.
When I make changes in projectA, in order to completely test it, I need to run tests in projectAB (these tests can not be moved into projectA).
What I want is to make changes in projectA, and instantly run tests in projectAB.
Naive schema: change projectA, publish projectA, test projectAB looks too complex.
Idealy for me, I'd like to set in my IDE to override projectA.jar dependency with project A, so I can threat projectA and projectAB as the single project. But I havent found a way to do it.
I use IDEA as IDE and Gradle as a build system
Please consider using Gradle composite builds or Gradle multi-projects that were made exactly for this purpose.
I have a multi-module maven project. In every module there are unit tests. When I make clean install tests run before every module and if all tests in one module are success it build successfully. If one test failure all other tests in that module run successfully (or some run successfully, other failed). The build of module in what the first failure unit test is placed failed. Other modules are skipped.
I want such thing: first to run all unit tests in all modules, and after that if there is no failed tests build all modules, or if there is one or more failed tests in one or mode modules skip building of all modules. Can you help me with it?
run:
mvn clean test
mvn install -Dmaven.test.skip=true
note, if you have inter-module dependencies (which i assume you do), you probably can't really do this, as you will need to build the dependent jars before you can run the tests in the other module.
AFAIK its impossible in maven. You are trying to change a maven build lifecycle which is not allowed in maven. However there are a couple of configuration parameters you can pass to maven and this will affect the testing.
mvn install -Dmaven.test.skip
This won't run unit tests at all
mvn install -Dmaven.test.failure.ignore=true
This will cause maven to not stop and proceed the module building process even if there were failures during the test phase.
Hope, this helps
The problem is:
the modules probably have dependencies upon each other, and to resolve those dependencies, you have to build the modules in order, or they won't compile. So there's no sane solution to your problem.
Insane solutions would somehow aggregate the sources (and external dependencies) from all child projects and run compile and test on that conglomerate, but it would be such a monstrous hack that I'm glad they didn't do it.