Maven can't find parent POM - java

I am trying to build a maven project, but I have encountered problem.
pom has specified parent pom and maven can't find it. I actually have the parent pom, but I don't know where to place it or what should I do so maven knows about.
I'm new to maven so sorry if my question is stupid.

If you have the parent pom, you could try installing it.
When you run mvn install on a module the resulting artifact will be placed in your repository, so that it can be used from other modules.

I am using Netbeans, I ran -N versions:update-child-modules in Run Maven/Goals.
It worked! It took 5 minutes to build but, it did build the project, and that's the first time that it has.

http://maven.apache.org/guides/introduction/introduction-to-the-pom.html Example 1 and Example 2 are for Inheritance that can be usefull.

This happens when the different POM in the project. They do not have the same version.
For example if you have:
MyProject / EAR ..... MyProject / WEB .....
you need to have the same version in three POM

Same error for me.I resolved by updating the project with a new POM file(someone form my team accidently deleted it).

Related

Maven is successfully built with the current version of a dependency, but still references to an older version

I have the current version of the dependency successfully installed in the local mvn .m2 registry with mvn clean install (confirmed by cd into .m2 repository).
I then modified the pom.xml of the project to include the new version number:
<dependency>
<groupId>com.xyz.lib</groupId>
<artifactId>xyz-lib-abc-model</artifactId>
<version>1.4.0-SNAPSHOT</version>
</dependency>
Maven was able to build successfully with 1.4.0-SNAPSHOT, but when I accessed the project in IntelliJ, it linked to an old version (0.1.1-SNAPSHOT) instead of the current version.
When I checked the dependency tree using `mvn dependency:tree, I have:
[INFO] +- com.xyz.lib:xyz-lib-abc-model:jar:1.4.0-SNAPSHOT:compile
Which looks correct to me.
I have tried using <dependencyManagement> but then it makes the project failed to build, and failed to detect the model.
Anyone knows what's going on and how to get maven to pull the correct version?
Thank you in advance!
Try re-importing the dependencies from local m2 in IntelliJ like :
Open the project view in IntelliJ
Right click the pom.xml file and
select Maven - Reimport If this works for you IntelliJ will add the
dependencies to the project
Check the if the dependencies you need are added in File - Project
Structure - Project Settings - Libraries and File - Project
Structure - Modules - Dependencies
I have seen this issue with IntelliJ.
If you don't need the old version anymore, you can cd to .m2 directory and delete the older version manually.
But you need to keep the both versions, you can open the project as a fresh project using the pom.xml. This will solve the issue.
Try the following approach:
Close the project in IntelliJ
File --> Open ...
Find pom.xml of your project, not the idea project files
Open this pom.xml. It will re-build all the dependency model in accordance with the information found in this new pom.xml (that I assume doesn't have an old dependency anymore).
DependencyManagement section is irrelevant in this case - mention it because you've said in the question that you've tried this - so don't bother, it will save you some time :)
my first guess goes to the used maven type in your IDEA is not the one that you use in the terminal. :)
You can set up the installed maven instead of the bundled one.
Or another solution is that you proceed a “refresh/reimport” in pom.xml. It will investigate the classpath based on your pom.xml and refresh the ones that needed.
You should see the "Reimport button here
If you don't see Maven at all, that means. you haven't added your project to IDEA as a Maven project.
Please then do the following
1. Right Click on pom.xml
2. 2. Add as a maven project

Is there a way to get version information rather than "(without test code)" in Eclipse Project Explorer's Maven dependencies?

I have a multiple-module project using STS4/JDK10. When my modules appear in the Maven dependencies of another of my modules, they always show with '(without test code)" rather than a version such as "1.0.0.jar - {repository location}". I have used Run/Maven Install the jar to my Maven repository and I have used deploy to put in my Archiva repository. Some of these modules have Junit tests. Is there a way to resolve the issue?
Am I missing something in my module-info file or my pom?
This is not because of you missed anything in pom. In fact this is a feature in eclipse, related to maven.
To see the jar(as you are expecting), follow the below steps:
Right click on module->Maven->Enable Workspace Resolution.
These steps solve you problem.

Issue while adding a new maven module to a maven project

I've added a new maven module B to an existing maven project A.
Apart from module B, A contains additional 2 modules C & D.
I've properly defined the module B inside parent pom.xml.
I've also added the parent tag inside module B pom.xml. The versions of all the modules as the parent are 0.0.X-SNAPSHOT.
Now when I do a mvn clean install deploy, it always throws exception:
Failed to create archive: Could not find artifact B:jar:0.0.X-SNAPSHOT in central (https://nexus.xyz.com/content/groups/public) ,which kind-off makes sense.
Hence,as a last resort, I tried to manually push the file into the nexus repo using using mvn deploy:deploy-file command.
Now, if I again do mvn clean install deploy,it works smoothly.
But the problem re-appears when I try to release the project.
This time, it complains:
Failed to create archive: Could not find artifact B:jar:0.0.X in central (https://nexus.xyz.com/content/groups/public)
I tried with mvn clean install -U as well but in vain.
The problem doesn't appear for any other modules.
Kindly advise.Thanks.
Okay...after fiddling around with all sort of permutations and combination, I finally arrived at the conclusion.
Those who says that the reactor automatically sorts and resolves all dependencies on its own are incorrect.
It seems that the link below describes it all. Kindly look at the last point under "Reactor Sorting" section:
https://maven.apache.org/guides/mini/guide-multiple-modules.html#Reactor_Sorting
It suggests that the order in which the modules are defined are taken into consideration when no other rules applies.
I hope that helps other. :)

Intellij IDEA 2017.2 cannot resolve symbol

In Intellij IDEA 2017.2, I am trying to import an existing multi-module Maven project which builds fine outside the IDE via Maven. When the import is complete, I noticed that in one of the Maven submodules, a symbol is unresolved, lets call this submodule submodule-problem. The unresolved symbol is a class that is defined in another submodule, lets call that submodule-other. The thing is that in submodule-problem, other classes defined in other submodules at the level of submodule-other are found ok(those submodules are defined as dependencies in the pom file of submodule-problem). Furthermore, submodule-other isn't declared as a dependency in submodule-problem's pom file. But I should NOT have to do this because as I mentioned mvn clean install -Dmaven.test.skip=true works fine. So does mvn test-compile. I am using the latest Maven 3.5.0 and have instructed IDEA to use the same for the said imported project in the project's Maven settings. Note: I don't have permission to show the code or concerned POM files.
Things I've tried to resolve the issue so far are:
Invalidate caches and restart IDEA, many times
Re-import as Maven project, many times
Delete the .idea folder and all *.iml files from the said project and re-import as Maven project, a few times
Delete IDEA's system preferences folder and retry all previous steps again many times (this step was painful as I had to install all my plugins and configure IDE setting over again)
Imported the same project into Eclipse-Oxygen and saw that it doesn't have any issues with the importing of the project.
I have solved the problem. It turns out that it wasn't any problem with the IntelliJ IDEA IDE (at least I think not). In production, my top level project is a child project of another parent Maven project and so it's version in it's pom file references the parent's version using ${project.version}. Whereas in development it IS the parent with the lower level projects being it's own children. So in all pom.xml files, where ${project.version} was being used by my top level project to refer to the production parent and also in the children poms where they were referring to my top level project as their parent, I changed it to something like a literal like 1.0.0-SNAPSHOT and all problems went away, I didn't even have to re-import the project into the IDE.
Now, as I mentioned in the original post, even without having to do this, Maven had no problem building the project. I'd love to know why if anyone knows. Perhaps the IDE needs me to do this because it is trying to enforce some best practice? I was led to the solution by watching idea.log where it complained about some POMs being invalid and indeed in those pom files the version tag had a red squiggly underline.

How do I implement maven source dependency among sibling projects?

I have a java project that is composed of 3 sub projects that generate a .jar artifact each (and have sub-dependencies among them).
In addition there is a web projects that depends on the first 3 projects and generate a war file. The war file is my final artifact, i.e. what I ship my customers.
Additionally I have a parent module that encompasses all the other projects:
<modules>
<module>../core</module>
<module>../commons</module>
<module>../api</module>
<module>../web</module>
</modules>
I generate eclipse files (mvn eclipse:eclipse) and work with eclipse. The problem is if I modify one of the non-web projects I must manually install it before deploying the web project to my web container. How can I make that the web project depends directly on the source code of the others and not on the version installed in the repository.
In your web application properties (right clic on the project in the Package explorer, then "properties"), add the three modules (core, commons and api) in the "J2EE Module Dependencies" (the others modules must be opened in the Eclipse workspace).
Do you want to add a dependency on the source jars deployed to the repository?
If so you can do it by adding the sources classifier to the dependency. See this answer for more details.
If not, can you clarify further please.
I think your problem is that you are just building just the war project. If you are building it from the command line, then what you have to build is the parent module. "mvn package" in the directory that contains the parent module should be enough. Of course this means that you have to build all the packages every time, but that is the way maven works.
The dependency:tree goal by itself will look things up in the repository rather than the reactor. You can work around this by mvn installing, as previously suggested, or doing something less onerous that invokes the reactor, such as
mvn compile dependency:tree
Works for me.
Edit: D'oh! Posted this answer to the wrong question. Was meant to be answering this

Categories

Resources