I have two projects A and B managed with maven and B depends on A. (Additionally they both have external dependencies from the public repositories).
When I run mvn compile on A everything is ok.
When I run mvn compile on B it tells me 1 required artifact is missing.
Doing mvn install on A does not help. What should I do?
I should add that these are two different projects rather than two modules of 1 project. Help.
UPDATE
It was just a typo in the referencing pom.xml, which I discovered thanks to #Raghuram's comment
Doing mvn install should be enough - check there are no typos in your pom.xml files.
Either install it manually to your local repository or use a repository manager like Nexus.
I would, as Rohan mentions as a comment to your question, create a parent pom you can execute the install goal for, including your two "internal" projects as modules.
Related
I would like to generate two jars from the same maven project when executing a mvn clean install.
The only difference between the two jars, will be the content of the META-INF folder.
For the moment, I've my-app.jar, I would like to have now my-jar-xxx.jar and my-jar-yyy.jar.
How can I achieve this ?
Regards.
You should not be creating two maven jars from the same maven project. Why? This sonatype blog post should explain.
The same article also explains two ways in which you can still do it, if you want to
Using profiles
By doing two executions of maven jar plugin
Here is the related stackoverflow post as well.
First of all +1 for Raghuram recommendation. In his linked sonatype blog you get hints about doing what you want using the classifier to distinguish between your two jars. The jars belong to the same artifact in this case.
You can also use two different poms for two different builds and call
mvn -f pom-xxx.xml clean install
mvn -f pom-yyy.xml clean install
In each pom you can specify an own artifactId. That separates both artifacts a bit more than the classifier solution does.
Nevertheless the advice not to do this seems reasonable and I would follow the parent/module project layout suggestion.
I have many dependencies in pom.xml. As I go through my project, I installed dependencies which are not used anymore(due to trial and error).
So I deleted dependencies which are not used anymore in pom.xml.
Performed mvn clean then mvn install.
Does the dependencies which I deleted in pom.xml no longer exist in maven repository?
mvn clean do not clean your repository. It only cleans the project.
You can do it manually, as commented by #Arnaud, or you might prefer an automated way using the maven-dependency-plugin with the purge-local-repository goal on a project which declares your deleted dependencies only:
mvn dependency:purge-local-repository
With the help of Purging local repository dependencies you need to do that. But this is little bit tricky. So be careful while you are using it.
I think dependency:purge-local-repository and Optional Parameter excludes will help you.
excludes nothing but : The list of dependencies in the form of groupId:artifactId which should NOT be deleted/refreshed.
For full documentation see this.
I have a project, that has pom.xml and depends on lots of dependencies from outside (located far-far in internet..).
So, I want to download all those dependencies which I depend on to my "local repository".
This is my try (I do not need do compilation, so I use "validate" here. So I'm do not expect to have "target" folder in the end):
mvn validate -Dmaven.repo.local=C:\my\.m2\repository dependency:copy-dependencies
In the end - yes I have many dependencies been downloaded to "C:\my\.m2\repository", but some of them went to: C:\projects\myProject\java\trunk\target\dependency, like these ones:
junit-4.8.1.jar
log4j-1.2.8.jar
mockito-all-1.8.2.jar
Question is: how to make those to be downloaded to "C:\my\.m2\repository" but not to "target" of my project?
For now, because of that, another projects that depend on that are failing while building, because they are expecting to find "junit-4.8.1.jar" in local repo.
Another try:
mvn validate -Dmaven.repo.local=C:\my\.m2\repository dependency:resolve
Then those dependencies are not resolvable at all.
Could not resolve dependencies for project bla-bla-SNAPSHOT: The
following artifacts could not be resolved:
commons-lang:commons-lang:jar:2.4, log4j:log4j:jar:1.2.8,
junit:junit:jar:4.8.1: Could not find artifact
commons-lang:commons-lang:jar:2.4 -> [Help 1]
Maven did that because you invoked the goal dependency:copy-dependencies. It will copy the dependencies of the current module to
${project.build.directory}/dependency
See http://maven.apache.org/plugins/maven-dependency-plugin/copy-dependencies-mojo.html
I really can't imagine these dependencies did not get into your local repo. Fiddling around with a script may not be the solution to your problem. Try
mvn process-resources -U -Dmaven.repo.local=C:\my\.m2\repository
The -U option forces a download of all dependencies. I suggest using process-resources, although as of my understanding validate should be fine, too.
I have a Maven Java project with many modules and one meta-modul. And I want to run test. I use: mvn test command in console. But my test fails when compilation, because classes in other modules are not found. But in IDE Eclipse no errors. How can I fix that?
if you have well defined dependencies, use mvn install instead of mvn test. Running tests is included in install phase too and you'll get the modules you need for compilation into local maven repository.
Try to run mvn install. This compile, packages and runs tests. Then when everything is compiled you can probably run mvn test only. But you should not (IMHO) because only when you are running the full process you are sure that the newest versions of your classes are being tested. Do not worry about efficiency: maven does not compile classes if it already have them compiled. Only mvn clean install will rebuild everything from scratch.
Your models need to be free of dependency cycles!
Try to run mvn test from the folder where the parent pom is located.
(details)
If you do not have a parent pom with sub modules. Then you must first run mvn install for all the other of your modules where the module you want to test depends from.
(Eclipse does not need this, because it can resolve dependencies to other open projects directly)
But if all the modules belong to an single release cycle (all the modules will be released togeter with the same version) then it is may a better approach to use parent and child modules/pom -- because then you can run mvn test or mvn install for the parent pom, and maven will do it for all the childs in the right order. -- After you have installed all other modules, you can run mvn test on a single module until you update an other modul. -- Then you will need to install this updated modul too, or better run install for the parent.
I'm in the process of learning maven (and java packaging & distribution) with a new oss project I'm making as practice. Here's my situation, all java of course:
My main project is ProjectA, maven-based in a github repository. I have also created one utility project, maven-based, in github: ProjectB. ProjectA depends on a project I have heavily modified that originally was from a google-code ant-based repository, ProjectC.
So, how do I set up the build for ProjectA such that someone can download ProjectA.jar and use it without needing to install jars for ProjectB and ProjectC, and also how do I set up the build such that someone could check out ProjectA and run only 'mvn package' for a full compile?
(Additionally, what should I do with my modified version of ProjectC? include the class files directly into ProjectA, or fork the project into something that could then be used by as a maven dependency?)
I've been reading around, links such as this SO question and this SO question, but I'm unclear how those relate to my particular circumstance. So, any help would be appreciated. Thanks!
So, how do I set up the build for ProjectA such that someone can download ProjectA.jar and use it without needing to install jars for ProjectB and ProjectC
Assuming ProjectA is a JAR, you can create an executable JAR that bundles the dependencies with the Maven Assembly Plugin (and the predefined jar-with-dependencies descriptor) or with the Maven Shade Plugin.
how do I set up the build such that someone could check out ProjectA and run only 'mvn package' for a full compile?
You have to deploy the dependencies to a repository that can be read over HTTP and to declare this repository in your pom.xml. AFAIK, git-hub doesn't offer any facility for that. But any web hosting service with FTP access (or better, scp) should do the trick. If your project is open source, another option would be to use Sonatype's OSS Repository Hosting service.
Just in case, you might want to read this blog post but you won't learn much more things.
The easiest would still be to organize the 3 projects as a multi-modules maven project and to build all modules.
Additionally, what should I do with my modified version of ProjectC?
From a modularization point of view (assuming you found a solution for the above part about repository), it would certainly make sense to have it as a separate module, especially if there is an opportunity someone can use ProjectC outside your project.
You have to publish the code from the additional dependencies. Two options:
Use the maven-shade-plugin to create a maven artifact containing all the content of the B and C jars, and publish that under your own G/A/V coordinates.
Publish copies of B and C under your own G/A/V coordinates using the maven-deploy-plugin to your forge just as you will publish your own code. Different forges have different policies; but if you abide by the licenses of B and C you should be OK.