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.
Related
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
In new Maven projects in IntelliJ, I see 2 ways of declaring new dependencies:
Manually editing the pom.xml file, adding a <dependency/> declaration.
This automatically (maven auto-import is on) adds Maven: ... entries to the project .iml file and all is well.
Using the File -> Project Structure -> Dependencies menu. This only creates entries in the .iml file.
This seems like unwanted behavior. IntelliJ doesn't overwrite the .iml file when importing the pom.xml Maven file, but merges dependencies from the pom.xml and additionally-defined ones from the .iml.
I want to enforce a single way of adding dependencies in my team (using pom.xml only, for external mvn builds), and the ability to bypass the pom.xml and directly add dependencies to the .iml creates the illusion of a valid build (when in fact, it is not).
Am I missing something? How can I enforce one way of adding dependencies? Is there a way through which IntelliJ will add dependencies to the pom.xml file instead of the .iml files?
EDIT
In this question (IntelliJ IDEA + Maven what is the need for dependency entries in an iml file?) it is claimed that
This can be also used to experiment with dependencies without changing the pom.xml. Note that all the modifications you make will be reverted on next Maven import.
But this is not the behavior I see. The .iml file doesn't get reverted, but merged.
It sounds like you need a continuous integration environment.
This won't stop your team members adding dependencies in the wrong place, but it will ensure that is caught very early and flag it up that they need to add it to your pom, then it just comes down to education.
Pom.xml is only to be used by Maven, IntelliJ does pick up the dependencies from the pom.xml if you have configured your IDE properly. If you however, want to use maven solely, you can add the jars to your local maven repo and then call them from your pom.xml normally via the <dependency> tag.
You can learn how to add local jars here.
I'm hacking on a Maven-based project with a lot of dependencies; the project is normally meant to be developed in Eclipse but I need to work on it from the command line.
How to build+execute the project in a sane way? Something like mvn run, but of course Maven is not meant for running Java projects (for some reason).
The problem is specifying all the dependencies on java's commandline, I don't even know how to autogenerate that. I can currently deal with it using the assembly:single maven plugin (using the jar-with-dependencies descriptor) which will package the dependencies to a single .jar for me.
However, there really is a lot of dependencies and the assembly phase can take about two minutes, greatly disrupting my hack-test cycles so I'm looking for other ways to run the project with minimum build overhead - any recommendations, please?
Note: One possibility is running it in Eclipse once and capturing the java commandline. However, that's just a one-time hack, not a general solution in case I change pom.xml later or come to another project from the suite without Eclipse access anymore.
Have a look at the maven exec plugin
mvn exec:java -Dexec.mainClass="com.example.Main"
if you do this frequently, you can of course configure it via plugin configuration.
Regarding finding out project dependencies - you can use maven dependency plugin
http://maven.apache.org/plugins/maven-dependency-plugin/list-mojo.html
If you want to put them into file it'd be smth like
mvn dependency:list > dependencies.txt
See this question: How can I create an executable JAR with dependencies using Maven?. You can use the dependency-plugin to generate all dependencies in a separate directory before the package phase and then include that in the classpath of the manifest.
I see three solution to this:
onejar-maven-plugin - faster than assemlby with jar-with-dependencies descriptor
With onejar-maven-plugin, you'll (...) get a nice clean super jar with the dependency jars inside.
Spring Boot Maven Plugin - but this is dedicated to Spring projects
Maven Assembly Plugin with custom descriptor. This custom descriptor should grab all dependencies into lib folder, maven-jar-plugin should set Class-Path in Manifest.fm according to this new location. After this you can simply execute your program or zip your jar with lib folder as distribution.
After this is possible to run your program on your computer or any other with one command:
java -jar myjar.jar
If i want to convert an EAR project a maven project , do i need to add the module in the deployment assembly as maven dependency or just use the convert in m2eclipse without any further configuration.
Me personally I wouldn't attempt any kind of conversion of an existing project. I would add the poms, make sure that mvn clean install works on the command prompt and then create a new mavenized Eclipse project from the poms.
The main reason is that you current project settings are effectively wrong when you switch to Maven - the Maven poms are the truth and what feeds the Eclipse project setup, so you really do not want to make your life difficult and work against m2eclipse - let it do the project creation for you. Fresh.
You can install m2eclipse and then do the following as well.
Go to the project menu (right click on Package Explorer) > Configure > Convert to Maven Project
Open the pom.xml and right-click and choose Run As -> Maven Clean. Similarly Choose Run As -> Maven Install.
Note : Please ensure that your eclipse project settings are correct and classpath libraries are not absolute and you don't have any project specific environment variables defined in your workspace. Please take a backup of your project before you do this.This is to ensure we don't mess up the current stable project configurations. Once m2eclipse generates the pom.xml for your project, you can update and make changes to it to
fully obtain a mavenized ear build. hope this helps
You can also try creating new maven project with archetype selection of "jboss-javaee6-ear" and follow the similar structure for your project. Most probably you will need parent Pom and child poms per each module (ejb, war, jar etc). There are other few similar approach but almost all of them requires you to have mulitple POMs
maven-ear-plugin and JBoss AS 7
You can also go through all the examples for maven ear plugin to find settings suitable for you
http://maven.apache.org/plugins/maven-ear-plugin/
I ended up ditching ear for war :) single POM and even ditched the JBOss for tomcat/jetty :)
If you want to convert your existing eclipse dependencies into Maven dependencies, you can try the JBoss Tools (JBT) Maven integration feature, which contains an experimental conversion wizard, plugged into m2e's conversion process : http://docs.jboss.org/tools/whatsnew/maven/maven-news-4.0.0.Beta1.html.
So, all you have to do is, as Keerthi explained, right-click on your project and Configure > Convert to Maven...
If your dependencies already are maven artifacts, it should work easily. If not, you'll need to convert them to Maven (if they're workspace projects) or make them available in your maven enterprise repository, before converting the EAR project.
JBT (requires Eclipse JavaEE) can be installed from http://download.jboss.org/jbosstools/updates/stable/kepler/ or from the Eclipse Marketplace (See https://marketplace.eclipse.org/search/site/jboss%2520tools)
We recently started using maven for dependency management. Our team uses eclipse as it's IDE. Is there an easy way to get eclipse to refresh the maven dependencies without running mvn eclipse:eclipse?
The dependencies are up to date in the local maven repository, but eclipse doesn't pick up the changes until we use the eclipse:eclipse command. This regenerates a lot of eclipse configuration files.
Have you tried using the m2eclipse plugin? I use it with eclipse and it maintains the eclipse .classpath when I add dependencies. It'll also check for updated dependencies.
You generate the special eclipse files with mvn eclipse:eclipse, but once you've done that, you should let a plugin handle the dependencies while inside eclipse.
That's how we do it at my work place, and it generally works well.