How to not pull module (dependency) from settings.xml servers? - java

I have the following project package structure.
parent
|- module1
|- module2
|- module3
I am able to include module3 as a dependency in both pom.xml files of module1 & module2. This gives me access to all of the dependencies & code from module3.
<dependency>
<groupId>my.group</groupId>
<artifactId>module3</artifactId>
<version>1.0.0</version>
</dependency>
However, when I run maven commands such as dependency:tree on the pom file of module1 or module2, maven will try to search on certain <servers> that are listed in my settings.xml file in order to try & download module3 as an artifact. module3 is not deployed to any <server> at the moment so, the maven command fails with following error
[ERROR] Failed to execute goal on project module1: Could not resolve dependencies for project my.group:module1:jar:1.0.0-SNAPSHOT: Failed to collect dependencies at my.group:module3:jar:1.0.0-SNAPSHOT: Failed to read artifact descriptor for my.group:module3:jar:1.0.0-SNAPSHOT: Could not transfer artifact my.group:module3:jar:1.0.0-SNAPSHOT from/to MyServer (https://example): Access Denied to: .......etc.
Ideally, module3 would not be deployed at all as an artifact but, instead it might simply have <packaging>pom</packaging>. module3 is just some module that should only be used by module1 & module2. Also, FYI the dependency tree of module3 builds perfectly fine.

Dependencies should never be of packaging pom. The need to be proper JARs and also need to be deployed to the repository.
Usually, you run build commands on the parent of the multi module project. If you want to restrict the build to one module, use -pl.

As far as I understand the question, the following maven module are part of the same reactor:
parent
|- module1
|- module2
|- module3
parent should have:
<modules>
<module>module1</module>
<module>module2</module>
<module>module3</module>
</modules>
Otherwise, Maven will not look in the file system but in the local repository.
Also, to my understanding, in your example module1 and module2 are two jar packaged module (eg: <packaging>jar</packaging> or omitted) but parent and module3 are two pom packaged module (eg: <packaging>pom</packaging>).
I suppose you want to create some kind of module importing only dependencies without code, in which case you should import it using:
<dependency>
<groupId>my.group</groupId>
<artifactId>module3</artifactId>
<version>1.0.0</version>
<type>pom</type>
</dependency>
Strange as it may be, this should work.
You can also use --offline to force maven to not go online.

Make sure the version of the module is correct.
Normally, when you run "mvn clean install" in parent project, all modules will be built, Order builds module3 -> module1 and module2. module3 is always built first.
Thanks

Related

Plugin dependency on an internal module

I have many modules in my project and let's say two of them are module A and module B. I have specified a dependency on the JAR of module A under the plugin tag of the pom for module B.
POM for module B:
<plugin>
............
............
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>module-A</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
The issue I am facing is that before the build begins i.e. before the JAR for module A is created, pom for module B is getting scanned and I am getting error that says:
"The POM for module A is missing, no dependency information available"
I do not have access to an online repository where I can host JAR for module A. How can I go about doing this locally? How do I ensure that JAR for module A is present locally before this scan takes place?
Usually, Maven determines the correct build order automatically.
I do not know whether plugin dependencies are accounted for as well.
In case of doubt I would move module-A before module-B in the list of modules in the main POM.

Maven: classes folder generated in multi-module maven project is empty

i have 3 modules in my maven project , each of the modules generate a jar file.
And then i have a 4th module that generates war out of these jars
Here is my POM which is parent of all modules
<modules>
<module>A</module>
<module>B</module>
<module>C</module>
<module>DWAR</module>
</modules>
IN DWAR's pom , I have specified dependencies on all the three modules A,B,C
<dependency>
<groupId>yyyy</groupId>
<artifactId>A</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
.
. And So on.
My war builds successfully, the lib folder of war contains all the jars, but classes folder is empty.
But in each of the modules A,B,C classes folder is populated with compiled classes.
What am I missing?
What you describe is the expected behaviour: Your war contains the three jars. The war itself has no java source files, so its classes folder is empty.
Building a war does not unpack the included jars, but adds them into the war as a whole.

Maven pom.xml adding another project

I ve got my maven web project and i want to add my ejb project (the same worksapce) as a liblary. How to make it in the pom.xml?
Do I think in a right way?
Assuming the MyEjbProject is not another Maven Project you own or want to build with maven, you could use system dependencies to link to the existing jar file of the project like so
<project>
...
<dependencies>
<dependency>
<groupId>yourgroup</groupId>
<artifactId>myejbproject</artifactId>
<version>2.0</version>
<scope>system</scope>
<systemPath>path/to/myejbproject.jar</systemPath>
</dependency>
</dependencies>
...
</project>
That said it is usually the better (and preferred way) to install the package to the repository either by making it a maven project and building it or installing it the way you already seem to do.
EDIT: If they are, however, dependent on each other, you can always create a separate parent project (has to be a "pom" project) declaring the two other projects as its "modules". (The child projects would not have to declare the third project as their parent). As a consequence you'd get a new directory for the new parent project, where you'd also quite probably put the two independent projects like this:
parent
|- pom.xml
|- MyEJBProject
| `- pom.xml
`- MyWarProject
`- pom.xml
The parent project would get a "modules" section to name all the child modules. The aggregator would then use the dependencies in the child modules to actually find out the order in which the projects are to be built)
<project>
...
<artifactId>myparentproject</artifactId>
<groupId>...</groupId>
<version>...</version>
<packaging>pom</packaging>
...
<modules>
<module>MyEJBModule</module>
<module>MyWarModule</module>
</modules>
...
</project>
That way the projects can relate to each other but (once they are installed in the local repository) still be used independently as artifacts in other projects
Finally, if your projects are not in related directories, you might try to give them as relative modules:
filesystem
|- mywarproject
| `pom.xml
|- myejbproject
| `pom.xml
`- parent
`pom.xml
now you could just do this (worked in maven 2, just tried it):
<!--parent-->
<project>
<modules>
<module>../mywarproject</module>
<module>../myejbproject</module>
</modules>
</project>

Maven does not pick up war dependency in pom.xml

I have a multi module Maven project. Parent project and then two other modules, one of which builds the war through its pom.xml.
Parent Project
---- Java Project
---- War Project
I build the war from parent project. There is another external war dependency in War project's pom.xml. Jars in that project are needed to build a specific profile, which is specified in War project's pom.xml. Maven cannot get those jars from war dependency. I ran the following command
mvn install:install <information about war>
to put it in local.m2 repository, but Maven doesn't pick anything from that dependency. I understand that Maven processes war dependencies differently than it does a jar dependency but I am unable to understand as to how will it pick it up? Any help will be appreciated. Thanks.
Edit
This is how I try to include the war dependency
<dependency>
<groupId>com.example</groupId>
<artifactId>my-id-artifact</artifactId>
<version>1.0.0</version>
<type>war</type>
</dependency>
Also, I would like to mention that I use that maven war dependency in <overlay> tag.

Maven assembly JAR in EAR

For reasons that I won't go into, I need to build the following structure:
EAR
|
|-- Uber-JAR
|
|-- WAR
I can build the uber JAR with the Maven Assembly plugin, but when I try to include it in the EAR (built with the Maven EAR plugin) it includes a normal JAR version, which has no sources (because I'm using the uber JAR to pull all the sources in the project together).
How can I get the uber JAR included in the EAR?
This is one way to fix it. If there's a better way I'd like to know it :)
Just include:
<earSourceDirectory>${basedir}</earSourceDirectory>
<earSourceIncludes>/path/to/jar.jar</earSourceIncludes>
in the EAR plugin configuration.
EDIT: Seems I spoke too soon. In the project's parent pom I have all the modules listed to build, with the uber JAR above the EAR module (as the last two modules).
It won't build the whole project:
'Artifact <ARTIFACT> (included by module) does not have an artifact with a file'
EDIT (again):
Final Answer
So, finally, in the configuration for the Maven Assembly plugin, I have:
<configuration>
...
<finalName>myjarname</finalName>
</configuration>
This creates a JAR file called simply 'myjarname.jar'.
In the Maven EAR plugin configuration, I use the following structure:
<configuration>
...
<modules>
...
<ejbModule>
<groupId>com.mygroup</groupId>
<artifactId>myartifact</artifactId>
<bundleFileName>myjarname.jar</bundleFileName>
</ejbModule>
</modules>
</configuration>
This grabs the specific jar and puts it in the EAR. Voila!

Categories