I have a multi-module maven project which has a pom file with packaging type as jar as described below. Another module in the project depends on this jar. When executing command mvn clean install, everything works fine but when executing mvn clean install -DskipTests=true, the project throws an error complaining unable to resolve dependency for the jar.
<artifactId>project.artifact.id</artifactId>
<packaging>jar</packaging>
<name>Project Name</name>
<description>Project Description</description>
<dependencies>
....
</dependencies>
Do I need to include some jar plugin or any other workaround for the same ?
The problem was due to version mismatch. Verify the versions of dependencies included and check for any conflicting dependency versions.
Related
I'm working on a multi-module springboot-app that looks like this :
basedir
module - pom.xml
module2 - pom.xml
module3 - pom.xml <---- this project contains the Main class
pom.xml (parent pom)
and I've got a library.jar that can't be placed into our nexus for various reasons. So I've installed into to a project-local repository following with mvn install:install-file -Dfile=/path/myjar.jar -DgroupId=id.group -DartifactId=myjar -Dversion=1.0 -Dpackaging=jar -DlocalRepositoryPath=${project.basedir}/lib
I've added both dependency and repository into parent pom , because all 3 modules use this jar
...
<dependency>
<artifactId>myjar</artifactId>
<version>1.0</version>
<groupId>id.group</group>
</dependency>
...
<repositories>
<repository>
<id>lib</id>
<url>file:///${project.basedir}/lib
<repository>
</repositories>
But still, the the dependency is not being found, neither by IntelliJ nor when i try to create a JAR. When i do mvn clean install it ignores the local repositry and tries to download it from the nexus. Could it be my company setting.xml config that is at fault or is it the multi-module setup?
Your supplied sample seems faulty (the URL tag is not closed) - you could try to install your maven dependency locally as you did and then use the maven offline switch and see if it works
mvn -o install
I have set up a WildFly Maven project with a local dependency. I compile the library (mvn compile) which is used as a local dependency and install it (mvn install) in the local Maven repository. Doing this allows me to successfully compile the WildFly project using Maven. The problem I encounter is that it fails to deploy (mvn wildfly:deploy), because it can't find the classes referenced in the local library, throwing a NoClassDefFoundError exception as result.
The library dependency is included as follows:
<dependency>
<groupId>mygroup</groupId>
<artifactId>library</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
I'm using the WildFly Maven plugin. Is there anything I should be doing differently?
<scope>provided</scope> - when you say provided you are saying that this lib will be available at runtime and does not need to be compiled with the current jar.
Hence what the artifact that you build using mvn compile/install will not include that library dependency.
This means that the application container(wildfly) you are running in must provide the jar.
You are getting the error because you havn't provided the library.jar in your application container nor have to included in your build file.
There are two solutions:
Explicitly defined the dependency in you jboss configuration:
https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6.1/html/Development_Guide/Add_an_Explicit_Module_Dependency_to_a_Deployment1.html
Change the scope from provided to compile: <scope> compile </scope>
My hope was that it would be easy to get Maven to run our application on any machine by simply deploying the pom.xml and using the maven exec goal.
The main class to run is inside the jar which is produced from the same pom.xml. But it seems that, while Maven quite nicely includes all the dependencies on the classpath, the pom's jar does not get included, or else it cannot be resolved from the repository where maven deployed it (which is an internal not public repository).
The steps I followed:
run mvn deploy -- this deploys our jar on an internal maven repository
install maven on the target machine (not the same as the build machine)
deploy the pom.xml to the target machine.
try to run using mvn exec:java ... or mvn exec:exec ...
What I see is that Maven pulls all the dependency jars onto the classpath correctly, but does not pull in the jar described by the pom.xml.
I tried various configuration options in the pom.xml, but nothing seemed to work. First, tried to configure exec:java as shown in this answer, but Maven did not search the internal repository for that jar. (It did seem to check the public maven repositories though).
Second, I tried to switch to the exec:exec version and configure like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>com.ezxinc.tfix.TFix</argument>
</arguments>
</configuration>
<dependencies>
<dependency>
<groupId>ezxinc</groupId>
<artifactId>tfix</artifactId>
<version>0.0.3-SNAPSHOT</version>
<type>jar</type>
</dependency>
</dependencies>
</plugin>
The dependency shown there is the information for the jar which the pom.xml deployed into our internal repository.
Of course, everything works fine if I unjar the class files into target subdirectory beneath the one where the pom.xml is.
If it helps, the full pom.xml can viewed here.
I think you'll need to have a different pom.xml file rather than trying to use the same pom from the project being built in step 1 of your description. This separate pom file could then include the project in question as a dependency so that it will get downloaded and included in the classpath when running maven commands.
The problem is that maven assumes that the project being described by a pom file is going to be compiled form source rather than downloaded from a repository. Anything you want downloaded from a repository needs to be a dependency, and if you try to include the current project as a dependency of itself you end up with a problem where the project could never be built the first time since it hasn't already been built and deployed to the repository yet.
I have a jar file that is built only as a profile. How do I reference that in a <dependency/> block? Let's say it's groupId is com.mycompany, artifactId is test-jar, version is 2.0 and profile is customBuild.
From the project you are building run mvn install, which will install the jar locally in your .m2 directory. Then you can reference it as a regular dependency using
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>test-jar</artifactId>
<version>2.0</version>
</dependency>
in your dependent projects.
I'm developing a maven project with several modules in eclipse. The parent pom.xml declares all submodules, and every submodule contains a pom.xml with a reference to the parent. Some submodules are dependent on other submodules, so I have added them as a dependency (m2e finds them when searching for dependencies). However, when I try to run a submodule outside eclipse using jetty (mvn -pl submodule jetty:run), I get the error that it is missing the other submodules.
In other words, and more elaborate: there's parent, sub1 and sub2. sub2 depends on sub1. I added
<modules>
<module>sub1</module>
<module>sub2</module>
</modules>
in the parent and
<parent>
<groupId>group</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
In both sub1 and sub2, and
<dependency>
<groupId>group.parent</groupId>
<artifactId>sub1</artifactId>
<version>0.0.1-SNAPSHOT</version>
</depdency>
in sub2.
When I run:
mvn -pl sub2 jetty:run
I get:
[INFO] Failed to resolve artifact.
Missing:
----------
1) group.parent:sub1:jar:0.0.1-SNAPSHOT
How can I get maven to find the submodule dependencies?
Have you tried running mvn install in your parent project before running Jetty in the submodule? This will install your jars in your local Maven repository, following which Maven will be able to find them.
(Or I could be grossly misreading the complexity of your question, in which case: please correct me.)