tags:

views:

1103

answers:

3

I'm trying to use Maven2 but my child projects cannot find the parent project.

Directory structure is as follows:

--parent
  --pom.xml
--child
  --pom.xml

Child pom.xml file looks like:

<parent>
    <groupId>com.mycompany.app</groupId>
    <artifactId>myapp</artifactId>
    <version>${app.version}</version>
    <relativePath>.../parent/pom.xml</relativePath>
</parent>

However when I use maven it doesn't even seem to look in the relative path, it seems to try and download it from the maven repository. It's obviously not in the repo. I want it to look at the relative path. What am I doing wrong? Here's the error message:

[INFO] Scanning for projects...
Downloading: http://repo1.maven.org/maven2/com/mycompany/app/myapp/${app.version}/myapp-
${app.version}.pom
[INFO] Unable to find resource 'com.mycompany.app:myapp:pom:${app.version}' in reposit
ory central (http://repo1.maven.org/maven2)
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).


Project ID: null:web:jar:null

Reason: Cannot find parent: com.mycompany.app:myapp for project: null:web:jar:null for
 project null:web:jar:null
+1  A: 

It should be:

<parent>
    <groupId>com.mycompany.app</groupId>
    <artifactId>myapp</artifactId>
    <version>${app.version}</version>
    <relativePath>../parent/pom.xml</relativePath>
</parent>
rodrigoap
That's no the issue (was just a typo IMO), this doesn't work.
Pascal Thivent
This still helped, maven documentation online ( http://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Example_2 ) actually uses ... which I think is a typo on their website
vagabond
+3  A: 

To my knowledge, variable expansion doesn't work in the parent element (see MNG-624 and comments for background around this), you need to set the version explicitly:

<parent>
  <groupId>com.mycompany.app</groupId>
  <artifactId>myapp</artifactId>
  <version>1-SNAPSHOT</version><!-- or whatever version you use -->
  <relativePath>../parent/pom.xml</relativePath>
</parent>

By the way, if you want to use the same version for all your modules, you should simply inherit it in your child project i.e. not override it (there is no real need for an ${app.version} IMO), not the other way around.

Pascal Thivent
+3  A: 

You can't use a property for the parent version - it must match. At the moment this is required for the build to be reproducible at a later date. A number of people are tracking this on issue http://jira.codehaus.org/browse/MNG-624

Brett Porter