How to compile pom.xml without generating project in Maven? - maven-2

I have pom.xml file that contains dependencies and files to checkout from svn so there is no no need to generate project. I just need these libraries and those files, so is there any way to get them without generating a project with maven directory structure?

I'm not sure from your question what do you want. If you have pom.xml file and you want to download all dependencies defined in it, you can call
mvn dependency:copy-dependencies
For more options look maven copy-dependencies task page
If you are asking how to create pom that will contain no code, but only dependencies, you can do that by specifying pom packaging.

Related

How to deploy pom.xml as SNAPSHOT with maven?

I have a pom.xml and i want to use it as the parent pom.xml of my project.
and want to make the name for the pom.xml which was uploaded on Nexus like ABC-root-pom-2.0.0-SNAPSHOT.pom
so could anyone tell me what the command is using maven ?
Thanks
Do not worry about what name the pom will have on the repository manager. The Maven repository format dictates that.
To get a Maven project with pom packaging deployed you have to do the normal steps of adding the distributionManagment to the pom and the credentials to the settings.xml. Then you run
mvn clean deploy
and thats it. Your other project can then reference it. An example for such a pom project is my progressive-organization-pom.

Convert web application project to maven project and convert corresponding .classpath file to pom.xml

Is it possible to convert project .classpath file to pom.xml after converting a simple web application project to maven project? Because if my project uses many jars and I want to convert it to maven then I will do configure->convert to maven but then it is not possible to add all the jars dependencies in pom.xml manually. So is there any tool to convert this.
First there is no tool to do such things. The problem is usually that you have a larger number of dependencies which you don't need to put into the pom.xml file, cause Maven handles transitive dependencies which means you only need to add only direct dependencies. The best thing is to look at the current projects jar files and try to find them in Maven Central and cut&paste the information form the search output into your pom. And of course test the build via Maven on command line.

maven release:perform and parent pom

I have a library which I "mavenized" recently and put into a local git repository.
In order to lock some plugin versions I created a simple parent pom which defines the plugin versions via pluginManagement (the parent pom file is not checked into any SCM repository). I specify the parent pom in my libraries pom file:
<parent>
<groupId>org.my.company</groupId>
<artifactId>superpom</artifactId>
<version>1</version>
</parent>
I use default directory structure.
When I try to perform a release using the release plugin I run into a problem.
mvn release:prepare runs fine however when I run mvn release:perform maven checks out the corresponding tag from my local git repository into the target/checkout folder and tries to run the deploy goal.
However the build fails with the error message that it can't find the parent pom file defined in my library pom file.
I assume that's related to the fact that maven tries to find the parent pom file in the target folder and it is not available there.
Is there an easy way how to solve this problem?
Update:
I have multiple unrelated GWT libraries which should share the common company parent pom file in order to specify plugin versions.
The parent pom is just used for defining some default versions and won't contain any module definitions because all GWT libraries are unrelated.
The GWT library are really simple and have no real dependencies to any other libraries apart from the default ones (gwt, junit)
Update2:
I solved the problem by installing the superpom into my local repository by running mvn install in the folder of my superpom.
The first fail you did is not to versionise the parent pom where you defined the pluginManagement area. This is the first step you must do put the pom.xml which you like to use a parent. Secondly you have to put the information about the VCS into the scm area of that pom. After you cleaned up everything you must do a mvn release:prepare release:perform of the parent pom. After that you are able to use it as a parent in your other projects. Furthermore you should define the distributionManagement area in your parent pom.

Using Maven ant task to install jar to local repository

At the end of my ant build id like it to call the equivalent of the command line call
mvn install:install-file -Dfile=my.jar -DgroupId=com.company.project -DartifactId=my_project -Dversion=1.0 -Dpackaging=jar -DgeneratePom=true
so that it will add the newly built jar to a maven repository which another project will rely on.
Ive tried using the maven-ant-task and have added the maven-ant-task jar to the ant built project and the following code to the build.xml:
<target name ="minstall" depends="jar">
<artifact:pom id="maven_install" file="maven_install.xml" />
<artifact:install file="${out.dir}/my_project.jar">
<pom refid="maven_install"/>
</artifact:install>
</target>
but seem to be missing something as it wont work for me. To begin with i get the error in the build.xml (ant build file) saying
The prefix "artifact" for element "artifact:pom" is not bound.
What am I doing wrong. I am fairly new to ant?
On a realted question what is the purpose of the associated POM file? I would not normally have a POM in this project as it is an ant build
Perhaps maven-ant-task jar is not installed, i.e. not in your ant CLASSPATH. You can follow this instruction for this.
As mentioned previously, you need to make sure the tasks are defined in your ant script, and the artifact namespace is understood.
The POM file is used (in this case) to tell the Maven repositories the dependencies of the JAR you are putting in the repository. The POM should also specify the JAR's identification information (groupId, artifactId, version number, license, etc.).
Strictly speaking, you do not need an external POM, you could define the information in your build.xml file as follows:
<!-- Assuming tasks defined, and 'artifact' namespace exists -->
<artifact:pom id="maven_install" groupId="com.whatever" artifactId="some-jar"
version="1.0" packaging="jar">
<dependency groupId="..." artifactId="..." version="..."/>
<dependency groupId="..." artifactId="..." version="..."/>
<license name="apache" url="http://www.apache.org"/> <!-- can be omitted -->
</artifact:pom>
<target name ="minstall" depends="jar">
<artifact:install file="${out.dir}/my_project.jar" pomRefId="maven_install"/>
</target>
When you install the JAR in the 'minstall' task, the POM should be generated with the appropriate dependencies in the local Repository.
That message means you are missing an xmlns:artifact attribute in your build.xml. Have a look at the installation page in the docs for an example.
As to the purpose of the POM file, it's mostly metadata so that maven can figure out dependencies properly. In a real maven build it also describes how to build, test and package. But in your case all that is done by ant instead.
I think that it makes no sense to put such commands in Ant's build.xml. If you want to have your jar file installed in your maven repo just use mvn install command.
Besides that, I guess that you are somehow confusing the purpose of Maven and Ant tools in your project. What I'd suggest is to use Maven as your main build tool. You can configure invokation of Ant targets in your POM file if you really need that. Personally, I think it is the best solution to have Ant called by Maven. Maven goals (such as clean, test, package, install and so on) are very simple to use and powerful (I guess that you can read it in every Maven tutorial).

How to avoid the dependencies of jar files to be included in the war build

I have customized pom.xml in maven to build a war file, for which i am compiling few class files which in deed depends on some jar files. Which i have included them as dependencies.
The build was successful but end result puts me in trouble now i have those class files included in my war which i don't want it.
So can you please help me to get rid of jar getting included in lib folder of war.
Regards
Gnash-85
You just have to change the "scope" of your dependencies in the Maven pom from "compile" (by default) to "provided". The "provided" libs won't be included in the final war file.
All options are listed on the Maven documentation.