You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by geoffh <ha...@yahoo.co.uk> on 2014/02/11 09:18:52 UTC

Adding dependency management to parent pom causes errors

I have a Maven project that has a parent pom and 5 child poms
In the initial version each pom had specific dependencies declared
All the projects completed the 'mvn clean deploy' build with success

I wanted to change this to use the dependency management features 
 - where the parent pom declared the dependencies and versions and the child
poms just referenced the dependencies

I changed the parent and child poms to use dependency management, but then
got compilation errors on one of my child projects

[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile
(default-compile) on project clearswift-common-gwt: Compilation failure
[ERROR] Failure executing javac, but could not parse the error:
[ERROR] An exception has occurred in the compiler (1.7.0_25). Please file a
bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) 
after checking the Bug Parade for duplicates. Include your program and the
following diagnostic in your report.  Thank you.
[ERROR] java.lang.AssertionError: typeSig 19
[ERROR] at
com.sun.tools.javac.jvm.ClassWriter.assembleSig(ClassWriter.java:357)
[ERROR] at com.sun.tools.javac.jvm.ClassWriter.typeSig(ClassWriter.java:424)
...

In attempting to identify the cause, I started by just adding dependency
management to my parent pom
Simply adding  
<dependencyManagement>
</dependencyManagement>
around the dependencies in my parent pom, causes dependencies not be
resolved

Does anyone have any idea why using dependency management might cause
compilation errors
 - or why just adding dependency management to the parent pom would cause
dependency resolution errors
 
Thanks for reading and any help



--
View this message in context: http://maven.40175.n5.nabble.com/Adding-dependency-management-to-parent-pom-causes-errors-tp5784035.html
Sent from the Maven - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Adding dependency management to parent pom causes errors

Posted by geoffh <ha...@yahoo.co.uk>.
The problem is resolved

I started with a minimal child pom and ran 
mvn dependency:analyze
 - then added dependencies until I had all the relevant dependencies

I no longer get the compile failure

I attempted to identify the differences between the 'good' and 'bad' poms,
but without success

Thanks to all who replied
Geoff



--
View this message in context: http://maven.40175.n5.nabble.com/Adding-dependency-management-to-parent-pom-causes-errors-tp5784035p5784760.html
Sent from the Maven - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Adding dependency management to parent pom causes errors

Posted by Barrie Treloar <ba...@gmail.com>.
On 12 February 2014 20:12, Adrien Rivard <ad...@gmail.com> wrote:
> Hi,
>
> DependencyManagement is declaring dependencies(mostly for versions) and
> dependencies is using them,
> So in general you should have only dependencyManagement in the parent poms
> and only dependencies in the childs.
>
> Now there are exceptions, for example junit is generally used in all child
> projects , so you can add it in dependencies of the parent pom and it will
> be avaible in all childs.

Adding dependencies into the pom with modules is a bad idea,
There will always be an exception that breaks that rule.
Then you will be asking how do I remove a dependency from a child pom
- you can't, dont define it in the first place.

Typical exceptions would be poms whose sole purpose is to build an
assembly (zip file) for package management, or Ear poms, etc.

A best practice is to never have any dependencies in a pom that has modules.
If you want to share common dependencies between projects, then you
can look at using the inherit type relationship but that pom would be
a standalone pom with no module declarations.
Your top level project is an Aggregation pom to make running Maven easier.
See https://maven.apache.org/pom.html#Aggregation

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Adding dependency management to parent pom causes errors

Posted by Adrien Rivard <ad...@gmail.com>.
Hi,

DependencyManagement is declaring dependencies(mostly for versions) and
dependencies is using them,
So in general you should have only dependencyManagement in the parent poms
and only dependencies in the childs.

Now there are exceptions, for example junit is generally used in all child
projects , so you can add it in dependencies of the parent pom and it will
be avaible in all childs.




On Wed, Feb 12, 2014 at 10:33 AM, geoffh <ha...@yahoo.co.uk> wrote:

> Laird, Barrie
>
> Thanks for taking the time with some useful explanations
> I'd like to put more detail into my problem in the hope that you may be
> able
> to spot something I am doing wrong:
>
> I started off with parent and child poms with no dependency management -
> along the lines of:
>
> Parent pom (without dependencyManagement)
>
>                 <dependencies>
>                         <dependency>
>                                 <groupId>log4j</groupId>
>                                 <artifactId>log4j</artifactId>
>                                 <version>${log4j-version}</version>
>                         </dependency>
>
> .
> .
> .
>                 </dependencies>
>
> Child pom (without dependencyManagement)
>
>         <dependencies>
>                         <dependency>
>                                         <groupId>log4j</groupId>
>                                         <artifactId>log4j</artifactId>
>                                         <version>${log4j-version}</version>
>                         </dependency>
> .
> .
> .
>         </dependencies>
>
> As I said, 'mvn clean deploy' completed successfully with no compilation
> errors
>
>
> I then changed the parent and child poms to use dependency management -
> along the lines of:
>
> Parent pom (with dependencyManagement)
>         <dependencyManagement>
>                 <dependencies>
>                         <dependency>
>                                 <groupId>log4j</groupId>
>                                 <artifactId>log4j</artifactId>
>                                 <version>${log4j-version}</version>
>                         </dependency>
>
> .
> .
> .
>                 </dependencies>
>         </dependencyManagement>
>
>
> Child pom (with dependencyManagement)
>
>         <dependencies>
>                         <dependency>
>                                         <groupId>log4j</groupId>
>                                         <artifactId>log4j</artifactId>
>                         </dependency>
> .
> .
> .
>         </dependencies>
>
> I arranged that each child pom only referenced the dependencies it needed
> - with the parent pom having all dependencies required by all children
> After that I got the compilation error
> Interestingly, I got the same error trace when invoking 'mvn
> dependency:analyze'
>
> >The compilation error you're talking about looks like something more
> >substantial than a bad dependency--you're getting a compiler error from
> >within javac itself.
>
> However,  the compilation error did not occur in the situation without
> dependencyManagement
> If there is a genuine compilation error, would it be expected to show in
> both cases
>
> Is that the correct way to use dependencyManagement ?
>
> Thanks for reading and any help / suggestions
> Geoff
>
>
>
> --
> View this message in context:
> http://maven.40175.n5.nabble.com/Adding-dependency-management-to-parent-pom-causes-errors-tp5784035p5784252.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 
Adrien Rivard

Re: Adding dependency management to parent pom causes errors

Posted by geoffh <ha...@yahoo.co.uk>.
Laird, Barrie

Thanks for taking the time with some useful explanations
I'd like to put more detail into my problem in the hope that you may be able
to spot something I am doing wrong:

I started off with parent and child poms with no dependency management -
along the lines of:

Parent pom (without dependencyManagement)

		<dependencies>
			<dependency>
				<groupId>log4j</groupId>
				<artifactId>log4j</artifactId>
				<version>${log4j-version}</version>
			</dependency>

.
.
.
		</dependencies>

Child pom (without dependencyManagement)

	<dependencies>
			<dependency>
					<groupId>log4j</groupId>
					<artifactId>log4j</artifactId>
					<version>${log4j-version}</version>
			</dependency>
.
.
.
	</dependencies>

As I said, 'mvn clean deploy' completed successfully with no compilation
errors


I then changed the parent and child poms to use dependency management -
along the lines of:

Parent pom (with dependencyManagement)
	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>log4j</groupId>
				<artifactId>log4j</artifactId>
				<version>${log4j-version}</version>
			</dependency>

.
.
.
		</dependencies>
	</dependencyManagement>


Child pom (with dependencyManagement)

	<dependencies>
			<dependency>
					<groupId>log4j</groupId>
					<artifactId>log4j</artifactId>
			</dependency>
.
.
.
	</dependencies>

I arranged that each child pom only referenced the dependencies it needed
- with the parent pom having all dependencies required by all children
After that I got the compilation error
Interestingly, I got the same error trace when invoking 'mvn
dependency:analyze'

>The compilation error you're talking about looks like something more
>substantial than a bad dependency--you're getting a compiler error from
>within javac itself.

However,  the compilation error did not occur in the situation without
dependencyManagement	
If there is a genuine compilation error, would it be expected to show in
both cases

Is that the correct way to use dependencyManagement ?

Thanks for reading and any help / suggestions
Geoff



--
View this message in context: http://maven.40175.n5.nabble.com/Adding-dependency-management-to-parent-pom-causes-errors-tp5784035p5784252.html
Sent from the Maven - Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Adding dependency management to parent pom causes errors

Posted by Barrie Treloar <ba...@gmail.com>.
On 12 February 2014 11:51, Laird Nelson <lj...@gmail.com> wrote:
> Agreed wholesale.  I think the original poster was wondering why this
> stanza:
[del]

You did a good job there so I didn't add any value to the response.

> While we're on the subject of best practices in this area, we've also found
> that dependency managing the versions of even child <modules> pays off in
> the end.

Be careful here.
People get confused with what a module is.

A module is not a dependency.
I think of it as a handy shortcut to allow me to run a maven command
at the top and have the same command also run in any module
declaration.
Logically a module is a group of things that tend to get released
together. If that is not the case, then don't use a module.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Adding dependency management to parent pom causes errors

Posted by Laird Nelson <lj...@gmail.com>.
On Tue, Feb 11, 2014 at 4:48 PM, Barrie Treloar <ba...@gmail.com> wrote:

> This is also best practice.
>

Agreed wholesale.  I think the original poster was wondering why this
stanza:

<dependencies>
<!-- ... -->
</dependencies>


...when "wrapped" (replaced, really) thusly:

*<dependencyManagement>*
  <dependencies>
  <!-- ... -->
  </dependencies>
*</dependencyManagement>*


...suddenly {handwave handwave} made his dependencies stop {handwave}
resolving.  (The answer being of course that there is no longer a
<dependencies> section in this particular case; he replaced it—did not
augment it—with a <dependencyManagement> stanza.)

While we're on the subject of best practices in this area, we've also found
that dependency managing the versions of even child <modules> pays off in
the end.

Best,
Laird

-- 
http://about.me/lairdnelson

Re: Adding dependency management to parent pom causes errors

Posted by Barrie Treloar <ba...@gmail.com>.
On 12 February 2014 10:17, Laird Nelson <lj...@gmail.com> wrote:
> First, and foremost, it is template information.  If a given real
> <dependency> somewhere else omits a piece of information, then that piece
> of information is taken (if possible) from the <dependencyManagement>
> section.

This is also best practice.

Appliying DRY principles you pull up all the dependency information
from your child poms into your parent pom's dependencyManagement
section.
Then in your child poms you *always* omit the version information in
your dependency section.

This way you know that your project is using a consistent version of artifacts.
The last thing you want is for your project to be using a mish-mash of
GWT versions (1.0 in one project, 2.6 in another, etc).

This gives you one place to define the versions.
And when its time to upgrade then one place to make the change.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Adding dependency management to parent pom causes errors

Posted by Laird Nelson <lj...@gmail.com>.
On Tue, Feb 11, 2014 at 12:18 AM, geoffh <ha...@yahoo.co.uk> wrote:

> In attempting to identify the cause, I started by just adding dependency
>
management to my parent pom
> Simply adding
> <dependencyManagement>
> </dependencyManagement>
> around the dependencies in my parent pom, causes dependencies not be
> resolved
>

I'm not sure why the developers chose the words "dependency management" to
identify the particular XML section in question.  It's very confusing.

Think of the <dependencyManagement> section as serving two purposes.

First, and foremost, it is template information.  If a given real
<dependency> somewhere else omits a piece of information, then that piece
of information is taken (if possible) from the <dependencyManagement>
section.

Second, which is really an outgrowth of the first, it constrains the
versions of transitive dependencies that might be pulled in from somewhere
else.  I say this is an outgrowth of the first concern, because strictly
speaking your project never mentions a transitive dependency, so that
"piece of information" is missing just like, say, a version string.

Note as well that the stuff in the <dependencyManagement> section can be
made up.  That is, you can put dependency management elements in there that
don't actually pick out any dependencies in the world.  See my earlier
point about this being a template area.

Putting this all together, it still follows that you have to have *real*
dependencies defined.  If you simply wrap your "real" dependencies with
<dependencyManagement></dependencyManagement>, that is clearly not going to
work: you've now specified a template, but nothing that the template will
be merged into.

The compilation error you're talking about looks like something more
substantial than a bad dependency--you're getting a compiler error from
within javac itself.

I noticed that "-gwt" showed up in some of your artifact names; perhaps
something with GWT is not playing nice.

Hope something in here helps.

Best,
Laird

-- 
http://about.me/lairdnelson