You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by codingplayer <ro...@smartengine.at> on 2011/10/24 09:58:31 UTC
where to put common dependecies in multi-module project
Hi,
i'm wondering where to put my common dependenies in my multimodule project.
Let's say, we have a project called sandbox, with three submodules.
- sandbox-core
- sandbox-service
- sandbox-web
Existing dependencies:
- sandbox-service has a dependency to sandbox-core
- sandbox-web has a dependency to sandbox-service
So practically, all dependencies of sandbox-core, will be transitive
dependencies for the other modules.
Let's say i want to use slf4j as logging framework, which should probable be
used in all modules and all of them should also use the same version.
I see different approaches on this:
- i could add the dependencies to the parent pom (sandbox)
- i could also only define a property for the version, e.g.
${slf4j.dependency.version} in the parent pom (sandbox) and actually add the
dependency on core level (sandbox-core)
- i could also simply add the dependency (plus version) to the core level
(sandbox-core)
I already had some problems, when not building the whole project (on
sandbox) level, that not all dependencies have been resolved in my leave
module (sandbox-web).
So i assume when putting the dependencies in the sandbox-core, one will
always have to build the whole project in order to have a working
sandbox-web module, while when putting them into the parent directly, the
dependencies would be retrieved by maven correctly anyway, since the
parent-poms are always taken intoconsideration, even when only the
sandbox-web is built.
So, what would be the best-practice on that?
What exact differences would be there between direct dependencies and
transitive dependencies?
Where should i put those common dependencies?
br
R.C.
--
View this message in context: http://maven.40175.n5.nabble.com/where-to-put-common-dependecies-in-multi-module-project-tp4931654p4931654.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: where to put common dependecies in multi-module project
Posted by Ron Wheeler <rw...@artifact-software.com>.
This is how we solve this problem in our case with a 70+ module project
with many 3rd party tools (Apache, JasperSoft, Spring, JBoss-Hibernate).
http://blog.artifact-software.com/tech/?p=121
Ron
On 24/10/2011 3:58 AM, codingplayer wrote:
> Hi,
>
> i'm wondering where to put my common dependenies in my multimodule project.
>
> Let's say, we have a project called sandbox, with three submodules.
> - sandbox-core
> - sandbox-service
> - sandbox-web
>
> Existing dependencies:
> - sandbox-service has a dependency to sandbox-core
> - sandbox-web has a dependency to sandbox-service
>
> So practically, all dependencies of sandbox-core, will be transitive
> dependencies for the other modules.
>
>
> Let's say i want to use slf4j as logging framework, which should probable be
> used in all modules and all of them should also use the same version.
>
> I see different approaches on this:
> - i could add the dependencies to the parent pom (sandbox)
> - i could also only define a property for the version, e.g.
> ${slf4j.dependency.version} in the parent pom (sandbox) and actually add the
> dependency on core level (sandbox-core)
> - i could also simply add the dependency (plus version) to the core level
> (sandbox-core)
>
> I already had some problems, when not building the whole project (on
> sandbox) level, that not all dependencies have been resolved in my leave
> module (sandbox-web).
>
> So i assume when putting the dependencies in the sandbox-core, one will
> always have to build the whole project in order to have a working
> sandbox-web module, while when putting them into the parent directly, the
> dependencies would be retrieved by maven correctly anyway, since the
> parent-poms are always taken intoconsideration, even when only the
> sandbox-web is built.
>
>
> So, what would be the best-practice on that?
> What exact differences would be there between direct dependencies and
> transitive dependencies?
> Where should i put those common dependencies?
>
> br
> R.C.
>
>
> --
> View this message in context: http://maven.40175.n5.nabble.com/where-to-put-common-dependecies-in-multi-module-project-tp4931654p4931654.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
>
>
--
Ron Wheeler
President
Artifact Software Inc
email: rwheeler@artifact-software.com
skype: ronaldmwheeler
phone: 866-970-2435, ext 102
Re: where to put common dependecies in multi-module project
Posted by Ansgar Konermann <an...@googlemail.com>.
Am 24.10.2011 11:08, schrieb codingplayer:
> And why not put it into the core module (e.g. sandbox-core) , since all
> other sub-modules would use the core anyway?
Because it violates Law of Demeter; quoting [1]:
"The advantage of following the Law of Demeter is that the resulting
software tends to be more maintainable and adaptable."
Best regards
Ansgar
[1] http://en.wikipedia.org/wiki/Law_of_Demeter
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: where to put common dependecies in multi-module project
Posted by Ron Wheeler <rw...@artifact-software.com>.
On 24/10/2011 10:43 AM, codingplayer wrote:
> Hi Jan,
>
> i get it now, declaring the dependencies in the parent-pom (or directly in
> each module's pom, where it will be used) leads to a proper binding of the
> library to the modules, and everybody who changes this dependency, should
> then be aware of the influences on the code.
That is one of the reasons why we use aggregation POMs. The decision
about what versions of 3rd party tools will be used in the project is
made at the team level and the developer only has to decide whether they
need JasperReports or not. If they do, then they add a single dependency
and know that it is correct and does not drag in any dependencies that
conflict with the Apache utilities that are included through the
"utilities" POM.
> While using transitive dependencies seem to be more or less hidden to those
> developers only using e.g. the web module.
>
> I also see the disadvantages (of the parent-pom approach) when you need to
> create some assembled artifacts.
>
> thanks for your help on this.
>
> br
> R.C.
>
> --
> View this message in context: http://maven.40175.n5.nabble.com/where-to-put-common-dependecies-in-multi-module-project-tp4931654p4932859.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
>
>
--
Ron Wheeler
President
Artifact Software Inc
email: rwheeler@artifact-software.com
skype: ronaldmwheeler
phone: 866-970-2435, ext 102
Re: where to put common dependecies in multi-module project
Posted by codingplayer <ro...@smartengine.at>.
Hi Jan,
i get it now, declaring the dependencies in the parent-pom (or directly in
each module's pom, where it will be used) leads to a proper binding of the
library to the modules, and everybody who changes this dependency, should
then be aware of the influences on the code.
While using transitive dependencies seem to be more or less hidden to those
developers only using e.g. the web module.
I also see the disadvantages (of the parent-pom approach) when you need to
create some assembled artifacts.
thanks for your help on this.
br
R.C.
--
View this message in context: http://maven.40175.n5.nabble.com/where-to-put-common-dependecies-in-multi-module-project-tp4931654p4932859.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: where to put common dependecies in multi-module project
Posted by Jan Fredrik Wedén <jf...@gmail.com>.
If you actually use a dependency (in code) in a module, that dependency
should always be a direct dependency of the module, either declared in the
module itself or in a parent POM. From my experience, declaring dependencies
(not dependencyManagement) in parent POMs comes with some disadvantages, but
from your description it sounds like this approach is a good fit for you. In
my case we had to do a lot of excludes in packaging modules (like ears, zips
etc) before we changed to a more "proper" way of declaring dependencies.
As for the other alternative you mention. Even if you have control over all
the artifacts in the build, as you seem do in this case, relying on
transitive dependencies from the core module for stuff you actually use in
other modules is a bad approach. It does not express true intent, and
conceptually these dependencies should be direct, as stated above. Also it
leaves your other modules open for "breakage" if someone in the future
intentionally or accidentally changes the core module in a way you did not
anticipate.
On Mon, Oct 24, 2011 at 11:08, codingplayer <ro...@smartengine.at>wrote:
> Hi Martin,
>
> thanks for your hint to the <pluginManagement> section.
>
> But actually, that is not exaclty what i want.
> Since i do not want to repeat defining each common dependency separately
> for
> each sub-module.
>
> This approach would be ideal, if i want to use this dependency in many
> sub-modules (but not all), so i could skip the definition in those
> sub-modules, where i do not need it.
>
>
> If a want to have a new common dependecy which shall be used for all
> sub-modules, i could simply add this dependency to the parent-pom, right?
> Why would i rather put in it each module individually, what would be the
> benefits?
>
> And why not put it into the core module (e.g. sandbox-core) , since all
> other sub-modules would use the core anyway?
>
> br
> R.C.
>
> --
> View this message in context:
> http://maven.40175.n5.nabble.com/where-to-put-common-dependecies-in-multi-module-project-tp4931654p4931809.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
>
>
--
- Jan Fredrik Wedén
Re: where to put common dependecies in multi-module project
Posted by codingplayer <ro...@smartengine.at>.
Hi Martin,
thanks for your hint to the <pluginManagement> section.
But actually, that is not exaclty what i want.
Since i do not want to repeat defining each common dependency separately for
each sub-module.
This approach would be ideal, if i want to use this dependency in many
sub-modules (but not all), so i could skip the definition in those
sub-modules, where i do not need it.
If a want to have a new common dependecy which shall be used for all
sub-modules, i could simply add this dependency to the parent-pom, right?
Why would i rather put in it each module individually, what would be the
benefits?
And why not put it into the core module (e.g. sandbox-core) , since all
other sub-modules would use the core anyway?
br
R.C.
--
View this message in context: http://maven.40175.n5.nabble.com/where-to-put-common-dependecies-in-multi-module-project-tp4931654p4931809.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: where to put common dependecies in multi-module project
Posted by Martin Höller <ma...@xss.co.at>.
Hi!
Define the versions of your dependencies in the parent's
<dependencyManagement> section. Define the actual dependency in every
submodule where you use it. Without the version!
The analyze goal of the maven-dependency-plugin can help you to find out if
you should declare a dependency or not.
hth,
- martin
On Monday 24 October 2011 codingplayer wrote:
> Hi,
>
> i'm wondering where to put my common dependenies in my multimodule
> project.
>
> Let's say, we have a project called sandbox, with three submodules.
> - sandbox-core
> - sandbox-service
> - sandbox-web
>
> Existing dependencies:
> - sandbox-service has a dependency to sandbox-core
> - sandbox-web has a dependency to sandbox-service
>
> So practically, all dependencies of sandbox-core, will be transitive
> dependencies for the other modules.
>
>
> Let's say i want to use slf4j as logging framework, which should probable
> be used in all modules and all of them should also use the same version.
>
> I see different approaches on this:
> - i could add the dependencies to the parent pom (sandbox)
> - i could also only define a property for the version, e.g.
> ${slf4j.dependency.version} in the parent pom (sandbox) and actually add
> the dependency on core level (sandbox-core)
> - i could also simply add the dependency (plus version) to the core level
> (sandbox-core)
>
> I already had some problems, when not building the whole project (on
> sandbox) level, that not all dependencies have been resolved in my leave
> module (sandbox-web).
>
> So i assume when putting the dependencies in the sandbox-core, one will
> always have to build the whole project in order to have a working
> sandbox-web module, while when putting them into the parent directly, the
> dependencies would be retrieved by maven correctly anyway, since the
> parent-poms are always taken intoconsideration, even when only the
> sandbox-web is built.
>
>
> So, what would be the best-practice on that?
> What exact differences would be there between direct dependencies and
> transitive dependencies?
> Where should i put those common dependencies?
>
> br
> R.C.
>
>
> --
> View this message in context:
> http://maven.40175.n5.nabble.com/where-to-put-common-dependecies-in-multi
>-module-project-tp4931654p4931654.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