Driver binary downloader maven plugin - across multiple modules - java

We've got a multi-module Selenium Maven project. Each module represents one application that is tested. We've also got a 'core' module which contains everything necessary for the whole setup (driver initialization, utils classes, etc.).
The problem is that we set the plugins and the repository map in every module's pom.xml - it's basically a copy-paste of the plugins and the repository map (this is it: Lazery)
My question is: is it possible to set the plugins and the repository map in our core pom.xml so that it would be used by all the other modules that have a dependency on that core module? I'm not very well-versed in Maven, so so far I haven't been able to find a solution to this.
EDIT: I have managed to solve the plugin issue by using pluginManagement. However, the issue of the RepositoryMap.xml is still there. I need to have the map in every project's test resources in order for the driver-binary-downloader to start the driver.

Resolved the resources problem by placing the Repository Map into the core module and giving the plugin the path.
As mentioned in my edit in the question: the plugin issue was resolved with the pluginManagement

Related

Maven test classloader doesn't include target/classes folder

I have a Maven project built on JDK 11, making full use of the Java Module System.
My problem is that I'd like to use Spring Data JPA repositories in my tests, but the Jpa Bean factory can't find my repository interfaces.
After some digging, I found that the reason is the classloader that Spring is trying to use to find the repository interfaces doesn't include the folder where the compiled main class files are saved, target/classes. Despite the fact that the Maven surefire documentation says that the directory should be included as the 2nd highest priority.
To better describe the issue, I created a demo GitHub repo, where I demonstrate my problem.
Without the module-info.java everything seems to work fine.

Intelij, Spring - Multi module project does not detect any dependencies when using classpath of parent module

I have a multi-module project. For simplicity, lets say there is a parent pom, and one child pom. I have all my dependencies in <DependencyManagement> in the parent pom, and then all of them in the child pom as well. Building the project with maven gives no issues. When running the project, while editing the configuration of the project and setting Use Classpath of module: child module, works fine. But when setting the Use Classpath of module: to parent module (that was the default), intelij gives errors for every dependency. For every dependency it says that package does not exist.
Error:(21, 27) java: package com.squareup.okhttp does not exist
even though I have okhttp in the dependencies, I use okhhtp and it works when using classpath of module : child. And i can even see that intelij detects the okhttp library because I can use CTRL+leftClick to navigate to the library, but when clicking run, I still get the error. Why is this happening, this error is given for every single dependency I have. If project structure or pom details are required, please comment and I will provide as much info as I can. Thank you!

maven shade in multi project setup filtering too much

How to properly set up maven-shade plugin in a multi-module maven project setup?
storyline
A (https://github.com/DataSystemsLab/GeoSpark) has a dependency on B (https://github.com/jiayuasu/JTSplus) is a fork of C (com.vividsolutions.jts)
Now for some tasks in my project I need to use D (http://www.geotools.org) which depends on another Version of com.vividsolutions.jts.
How can I use both jars in a single project? A simple dependency replacement unfortunately does not work here. Shading should be the solution.
first attempt - shading the parent pom
When I try to apply the maven-shadeplugin to the root pom of https://github.com/DataSystemsLab/GeoSpark/blob/master/pom.xml as outlined Using Maven shade plugin in a multi module project - NullPointerException a null pointer exception occurs
multi project setup
When following How to configure Maven shade plugin in a multi-module project? to set it up for a multi module build the maven build compiles at least. However, the generated jar is lacking the actual code of the geospark module. I can't see where this would be filtered.
My changes are available https://github.com/geoHeil/GeoSpark/commit/23d212aeeeacad8b7199da69366d583fc48edcf0
With the main changes being:
introducing a third module FinalModule
shading only enabled there replacing com.vividsolutions.jts with com.vividsolutions.jtsgeospark
Indeed, disabling magnification is the solution. Otherwise probably explicitly including desired artifacts would work as well.

How does maven resolve a parent pom?

I came accross a problem and I want to understand it.
Story
Maven version was 3.2.1. I had a multi-module project structure like this:
mainmoduleA
-pom.xml
-submoduleB
--pom.xml
--submoduleC
---pom.xml
-submoduleD
--pom.xml
--submoduleE
---pom.xml
The submodules are always the child of the module in the parent folder. None of them have relativePath in the parent element in their POM, which means as far as I know ../pom.xml. The problem was, that submoduleC has become a new dependency, and submoduleE was already depending on submoduleC. The version of the new dependency of submoduleC was managed in mainmoduleA. In the local repository and in the company repository was still an old version of mainmoduleA, which did not contain that managed version. The workspace folder structure however contained the correct mainmoduleA POM. If I have built submoduleE alone, I have got a warning that the transitive dependencies of submoduleC will be ignored because of the missing managed version, and the results were compilation errors.
Resolution Priority
What is the order of the possibilities used by maven to look up a parent pom?
Based on my experience above:
maven local repository
maven remote repository
tracking it down in the folder structure based on the relativePath tags of the parent tags.
Am I right with the statements above? Can you prove it somehow? I did not find any relevant documentation.

Migrating from ant to maven in Netbeans

Our software is written in Java and comprise many (7) projects.
These projects are Netbeans ant projects.
I'm considering to converting them to maven2.
Where can I find some hints for doing such thing?
Don't read that book. It will only make you confused. Read this book instead: "Maven - The definitive guide" http://www.sonatype.com/books/maven-book/reference/ .
Also, the maven site has a lot of information, but the structure is terrible so you'll need to use google to navigate in it.
Here is my suggestion:
Do this by hand, not with "automagic" "help" from the IDE. Maven integration doesn't work that good yet, not in any IDE.
Make sure you program project is divided into modules under a common umbrella module, so that each module produces a single binary artifact (jar, war,...) possibly accompanied by the javadoc of the source code behind that artifact, a zip with the source code etc. The basic principle is that each module produces a single artifact, containing all the non-test-code under that module. You can do this while the project is still built by ant.
Each module should conform to the standard maven directory layout. The build destination is under [module]/target/[output-type, e.g. "classes"]. The source code is under [module]/src/main/[src-type e.g. "java"] and [module]/test/[src-type]. The artifact consists of all the code under src/main, and none of the code under src/test, as it built to the target directories. You can do this while the is still built by ant.
Start by transforming the sub-module that has no dependencies on other modules in the project.
Now you can create the parent maven module pom.xml with artifact type "pom", consisting of one of the modules below. Make a child module for the first submodule (the one with only external dependencies), using the umbrella module as "parent". Remember that you need to specify version for the parent. Remember to add the child module as a "module" in the parent too. Always use ${project.version} as version in the child modules when you create multi-module projects like this. All modules under a parent must be released simultaneously in a single operation, and if you use this setting maven will make sure the version fields stay the same across all modules and gets updated everywhere during the release. This may make it difficult to re-use the existing numbering scheme, but that doesn't matter. You are never going to run out of version numbers anyway.
Add the necessary dependencies, and make sure you can build the parent and the child module together using the command "mvn clean install" from the parent module.
Proceed with the rest of the modules the same way. Dependencies to other modules under the same parent project should also use ${project.version} as the "version" they are depending on, meaning "the same version as this". NOTE THAT in order to build, the module you are depending on must be built using "mvn install", so that it gets deployed to you local (computer) repository. Otherwise the depending module will not be able to find the classes. There are NO source-code dependencies between modules in maven, only dependencies to built and packed versions installed in local and remote repositories. This can be very confusing if you come from ant-projects. Build from the root module until you get comfortable with this. It takes two days.
Don't use maven integration in IDEs. It is a bad idea. Use "mvn idea:idea" or "mvn eclipse:eclipse" to set up your workspace as a non-maven ordinary IDE project. The inter-module dependencies mechanisms in maven and the IDE aren't identical and will never be. Also, if you have several mavenized projects with dependencies in between, you want to have several of these in your workspace with dependencies set up between. You can do this with mvn idea:idea / eclipse:eclipse if you create a separate maven project file called "workspace.xml" (or whatever) in the same directory as parent module, set up as a multi-module project containing modules "." and "../otherproject" (only one-way reference here, no parent ref back). If you run "mvn idea:idea / eclipse:eclipse -f workspace.xml" you get a workspace with all these modules linked together. No IDE integration lets you do that. This sound like a lot of extra work, but the workspace.xml-file is really small. It doesn't have to contain all that dependency stuff and all that, only the reference to the modules you want to bind together in your IDE.
I did a succeful migration of NetBeans Ant project to Maven project using the instruccions by Joseph Mocker here: http://forums.netbeans.org/ptopic55953.html
I cite the important part:
close the project
rename the build.xml, nbproject files/folders to something so NB won't recognize them.
close and restart NB (so any memory cache knowledge of the project is gone)
copy in an empty pom from some other project.
open the project back up in NB (NB should now identify it as a maven project)
rearrange the files to follow the maven way (™)
This won't be an easy task since Maven2 expects the files to be organized in a specific way. Anyway Better Builds with Maven is a free book that should get you started. It will help you understand Maven and it also has a chapter on migration.
I discovered that the migration is not necessary. The real requirements that I need was automatic download of dependencies (libraries).
This is also achieved by Ivy which nonetheless uses maven repositories.
I solved converting project from ant to ant+ivy with IvyBeans.
I have built a script to migrate Ant builds to Maven. You can find more information here:
https://github.com/ewhauser/ant2maven
It won't help you with fixing your directory structure and or any additional Ant tasks, but it removes a lot of the tedious steps to get started.

Categories

Resources