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.
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>
I have the a project pom and a parent pom. The parent pom defines a dependency as follows:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.mycode/groupId>
<artifactId>common</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
My project pom inherits the parent and defines the dependency.
<parent>
<groupId>au.com.truelocal</groupId>
<artifactId>truelocal-parent</artifactId>
<version>develop</version>
</parent>
<dependencies>
<dependency>
<groupId>com.mycode</groupId>
<artifactId>common</artifactId>
</dependency>
</dependencies>
I used to build with Maven this way without issue.
I now want to start having a different version in parent, common and project.
I am going to use the maven versions plugin to set my version.
I am setting the parent version and version successfully however, maven keeps looking for the wrong version of common. E.g. if my project is building as version 1.0.0-4 then it looks for common-1.0.0-4 but I actually need it to get the latest version of common instead which could be for example 1.0.0-23.
Can i use the versions plugin to adjust my dependency version? How do I make it only apply to common and not other dependencies I may have?
mvn versions:set (I guess this is what you've done) sets the version of your project, respectively the project versions which are part of a multi module project.
It doesn't touch the versions of the dependencies, either they are configured in a parent pom within <dependencyManagement> or within <dependencies>.
You can adjust the dependency versions by several ways: mvn versions:display-dependency-updates , mvn versions:use-latest-releases , mvn versions:use-latest-snapshots.
Use mvn versions:help or mvn versions:help -Ddetail=true -Dgoal=use-latest-snapshots to get more informations.
I'm new to Maven and I created a new web app to "migrate" an old application and to start using Maven 3. This application uses some libraries (jars) and most of them are under the shared/lib folder in Tomcat (5.5) directory.
How can add these libs to Maven POM? Should I add them at all?
I forgot to mention that some of these jars cannot be found in Maven repository since are more like utility libraries that are common to most of the projects.
In the <dependencies/> section of the POM, you can declare the shared jar as a "system" scoped dependency. This scope recognizes a <systemPath/> child element, allowing you to point to the filesystem location on the local (build) filesystem.
See Maven "System" dependencies
example:
<project>
…
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>someDependency</artifactId>
<version>1.0.1</version>
<scope>system</scope>
<systemPath>${tomcatHome}/shared/lib/someDependency-1.0.1.jar</systemPath>
</dependency>
</dependencies>
…
</project>
Use
<dependency>
tags to specify the libraries. And if some of the libraries are not found in the maven repository. Specify the repository using
<configuration>
I have an in-development library project (module by IntelliJ definition) that i want to reference from other projects. How would i go about to reference that project in other projects ?
you can use whether Dependency or module tags in pom.xml of your project.
Depends on what you trying to do.
<dependency>
<groupId>com.mysubpro</groupId>
<artifactId>myproject</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
Or
<modules>
<module>myproject</module>
</modules>
You have to use mvn install goal. This will install your library to your local repository. Link to Maven Install Plugin. Once it is done you can have a dependency to it in your other projects.