I have my own java library created as maven project and has some dependencies included in pom.xml
I want to export project as jar and include it into others maven projects.
The problem is that I need to copy all dependencies from pom.xml of my library into maven projects where is imported my library to make it to work.
How to export my library to not be necessary to copy dependencies of my library.
That is easy to do; the central feature of Maven is that it manages the project dependencies for you.
You need to mvn install your project from the command line; that will install the jar and the pom files to your local repository.
You can then include your library as a Maven dependency in other Maven based projects; Maven will resolve the (transitive) dependencies for your project.
Normally you don't need to list all the dependencies in the project that imports your library. Maven should fetch them for you. What you need to do is to declare dependencies in your library.
Make sure you declare correct types of dependencies. Here is more info. In your case you need to make sure that dependencies you want to copy to the downstream projects are marked as 'compile'
There are tools that make 'Fat' jars by copying all dependencies inside. But they are mostly used to build the final project such as a deployable WAR file or a desktop app. Not in case of the libraries
Related
I have recently used the Maven Assembly Plugin and also the Maven Shade Plugin in order to create a FAT JAR containing a specific plugin and its dependencies.
I did this because during the build phases our company uses private servers with no access to the internet so I can't depend on public repositories.
So I have this FAT-JAR-WITH-DEP.jar and to test if it works with my module, I removed the original plugin jar from the maven repo and pasted this instead.
I also removed its dependencies. the POM file remained the same.
What happens is that it still tries to download the dependencies because of the pom file.
How do I use a FAT JAR as a plugin that already includes it's dependencies?
Sorry, but building such a fat jar is not a good idea. You are trying to manipulate the "inner structure" of Maven.
If you want to use Maven in an offline environment, copy all the relevant plugins and dependencies to your company Nexus/Artifactory. The easiest way to do this is run a build once against a public repository and then copy all the stuff that was downloaded through Maven.
I went through this link to import a gradle project as dependency into another gradle project. Is there a way to include a maven project as dependency into a gradle project?
If that Maven project is built somewhere else and deployed to a Maven repository, you can specify the artifact it produces as a simple compile dependency. If this Maven project is somehow a subproject of a Gradle multi-project build, I suppose you could hack it to work by simply ignoring the Maven POM file and perhaps adding a build.gradle to that project.
To use the solution described on the link that you provided - both projects must be gradle and included in gradle settings. Therefore you can use project closure to compile and depend on the project without building it explicitly.
I am not aware of any way to do this with maven project. I understand you use some maven plugins that you dont want to rewrite in gradle as simply can not find any equivalents etc. Often had that problem.
In this scenario I would suggest to build maven project and depend on a built jar in your gradle project.
Otherwise you could probably amend sourcesets in your gradle project to include maven classes. But I think it would be to complicated.
If I would be you I would turn it into gradle and try to replicate what you had using maven or just build the artifact and depend on it in dependencies closure.
Gradle is not that new anymore and there are many plugins that are superseding old good maven stuff.
In my maven eclipse project I see Maven dependency and Referenced Libraries. In some cases they have the same set of jars referring to M2_REPO. And in some they are entirely different. Leaves me confused as to why there are 2 different jar references in the same project.
Maven dependencies are added in pom file to a project. When you build the project, maven dependencies that you have added in pom file will be downloaded from the M2 repository.
Reference libraries are added manually for projects in Eclipse IDE.
When you leave confusing for those jar files, just add all libraries as maven dependencies.
Classes in both Referenced Libraries and Maven Dependencies are visible in Eclipse but Maven build can see only dependencies from pom. If you try to build the project with maven it may fail because of this
I have a Java Maven project, where I use a commercial, third-party dependency which I'm not allowed to redistribute. I use Appassembler Maven Plugin in my project to collect all dependencies and build a startup script.
Now I want to zip the Appassembler target folder and send it to a client, including all open source dependencies, but excluding the proprietary dependency. How can I configure Appassember to exclude this JAR?
Is it possible for maven plugin to manage only dependencies and nothing more.
I work with "strange" maven project, and want Eclipse/maven plugin only to read dependencies from pom.xml and add it to project classpath. And nothing more.
I don't want it to set exclusion filters, source folders and output folders, or to overwrite other dependencies.
Also, pom.xml is not located in the source folder of Eclipse project. I know I could use mvn eclipse:eclipse task manually, but it mess with my .classpath and .project files, which I don't want to merge manually.
To summary, I want that all dependencies from pom.xml are automatically managed by plugin, but for plugin not to touch anything else.
EDIT: The problem is that whenever something in pom.xml changes, maven plugin changes my project configuration.
EDIT: It has to be maven since there is already pom.xml which I can replace with sbt or ivy or lein or anything eles.
Does it have to be maven? If you don't need any of the plugins, or project organisation you could use apache ivy instead.
Or you could use a even more simple one like SBT
if you have to use maven, just strip out the plugins from the pom.xml file and only add the dependencies and repos and use an IDE to launch the aplication or create a jar.
you will need to run mvn commands thought if you change the dependencies.