You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by João Pedro <pe...@gmail.com> on 2013/11/05 11:50:27 UTC

How to install the impl module for a api dependency in maven

I have a multi-module maven project structured in something like this:

parent
   |
   |-presentation
   |+services
   |    |-services-api
   |    |-services-impl
   |+data-access
   |    |-data-access-api
   |    |-data-access-impl
   |-+connector
   |    |-connector-api
   |    |-connector-implA
   |    |-connector-implB
   |-...

The presentation module is packaged in a war and it depends only on the api
modules.

When i run the install goal the only dependencies that the war installs are
the api modules. To choose wich impl modules to install in the presentation
module i'm using profiles that add the dependency to the impl modules at
build time depending on the profiles selected.

>From what i've been reading i don't think that this is correct usage for
the maven profiles.

What is the best way to tell maven to add the chosen impl to the
presentation module?


I would like to keep the dependency to only the api module but with the
usage of profiles, if the profile is active, the dependency is there and no
compilation errors will happen when i reference a class of the impl
module...
thanks
-- 
Cumprimentos,
João Pedro

Re: How to install the impl module for a api dependency in maven

Posted by Anders Hammar <an...@hammar.net>.
>
> Thanks, i think that i can use the compiler scopes to resolve the
> dependencies.
>

Compile scope dependency is the default dependency scope. It is what you
probably already use.


> But in order to have one war per "flavor" i have to move all my resources,
> like jsp's, out of my war and into a child war project rigth? and create
> more than one top level war with the dependencies to the diferente impl
> modules.
>
> was this what you meant by one project per "flavour"?
>

You could use war overlays. Create the war projects as sibling modules.

/Anders

>
>
> On Tue, Nov 5, 2013 at 12:00 PM, Anders Hammar <an...@hammar.net> wrote:
>
> > I don't fully understand what you want to accomplish, but, as you point
> > out, profiles is not the right path. It almost never is. :-)
> >
> > What I think you want to do is to have compile scope dependencies to your
> > api artifacts from the impl projects. And then in the war project
> > ("presentation module") you declare deps to the artifacts you need (you
> > have a dependency to), which should include impl artifacts as they are
> > needed. In your war project I would assume that you have some kind of
> > compile time dependency to your impl code, and if so you need to declare
> > that. If you don't have a compile time dependency, then you have a
> runtime
> > dependency and then specify that (scope 'runtime').
> >
> > If you want different flavors of your webapp, then you create one war
> > project per "flavor".
> >
> > /Anders
> >
> >
> > On Tue, Nov 5, 2013 at 11:50 AM, João Pedro <pe...@gmail.com>
> wrote:
> >
> > > I have a multi-module maven project structured in something like this:
> > >
> > > parent
> > >    |
> > >    |-presentation
> > >    |+services
> > >    |    |-services-api
> > >    |    |-services-impl
> > >    |+data-access
> > >    |    |-data-access-api
> > >    |    |-data-access-impl
> > >    |-+connector
> > >    |    |-connector-api
> > >    |    |-connector-implA
> > >    |    |-connector-implB
> > >    |-...
> > >
> > > The presentation module is packaged in a war and it depends only on the
> > api
> > > modules.
> > >
> > > When i run the install goal the only dependencies that the war installs
> > are
> > > the api modules. To choose wich impl modules to install in the
> > presentation
> > > module i'm using profiles that add the dependency to the impl modules
> at
> > > build time depending on the profiles selected.
> > >
> > > From what i've been reading i don't think that this is correct usage
> for
> > > the maven profiles.
> > >
> > > What is the best way to tell maven to add the chosen impl to the
> > > presentation module?
> > >
> > >
> > > I would like to keep the dependency to only the api module but with the
> > > usage of profiles, if the profile is active, the dependency is there
> and
> > no
> > > compilation errors will happen when i reference a class of the impl
> > > module...
> > > thanks
> > > --
> > > Cumprimentos,
> > > João Pedro
> > >
> >
>
>
>
> --
> Cumprimentos,
> João Pedro
>

Re: How to install the impl module for a api dependency in maven

Posted by João Pedro <pe...@gmail.com>.
Thanks, i think that i can use the compiler scopes to resolve the
dependencies.

But in order to have one war per "flavor" i have to move all my resources,
like jsp's, out of my war and into a child war project rigth? and create
more than one top level war with the dependencies to the diferente impl
modules.

was this what you meant by one project per "flavour"?


On Tue, Nov 5, 2013 at 12:00 PM, Anders Hammar <an...@hammar.net> wrote:

> I don't fully understand what you want to accomplish, but, as you point
> out, profiles is not the right path. It almost never is. :-)
>
> What I think you want to do is to have compile scope dependencies to your
> api artifacts from the impl projects. And then in the war project
> ("presentation module") you declare deps to the artifacts you need (you
> have a dependency to), which should include impl artifacts as they are
> needed. In your war project I would assume that you have some kind of
> compile time dependency to your impl code, and if so you need to declare
> that. If you don't have a compile time dependency, then you have a runtime
> dependency and then specify that (scope 'runtime').
>
> If you want different flavors of your webapp, then you create one war
> project per "flavor".
>
> /Anders
>
>
> On Tue, Nov 5, 2013 at 11:50 AM, João Pedro <pe...@gmail.com> wrote:
>
> > I have a multi-module maven project structured in something like this:
> >
> > parent
> >    |
> >    |-presentation
> >    |+services
> >    |    |-services-api
> >    |    |-services-impl
> >    |+data-access
> >    |    |-data-access-api
> >    |    |-data-access-impl
> >    |-+connector
> >    |    |-connector-api
> >    |    |-connector-implA
> >    |    |-connector-implB
> >    |-...
> >
> > The presentation module is packaged in a war and it depends only on the
> api
> > modules.
> >
> > When i run the install goal the only dependencies that the war installs
> are
> > the api modules. To choose wich impl modules to install in the
> presentation
> > module i'm using profiles that add the dependency to the impl modules at
> > build time depending on the profiles selected.
> >
> > From what i've been reading i don't think that this is correct usage for
> > the maven profiles.
> >
> > What is the best way to tell maven to add the chosen impl to the
> > presentation module?
> >
> >
> > I would like to keep the dependency to only the api module but with the
> > usage of profiles, if the profile is active, the dependency is there and
> no
> > compilation errors will happen when i reference a class of the impl
> > module...
> > thanks
> > --
> > Cumprimentos,
> > João Pedro
> >
>



-- 
Cumprimentos,
João Pedro

Re: How to install the impl module for a api dependency in maven

Posted by Anders Hammar <an...@hammar.net>.
I don't fully understand what you want to accomplish, but, as you point
out, profiles is not the right path. It almost never is. :-)

What I think you want to do is to have compile scope dependencies to your
api artifacts from the impl projects. And then in the war project
("presentation module") you declare deps to the artifacts you need (you
have a dependency to), which should include impl artifacts as they are
needed. In your war project I would assume that you have some kind of
compile time dependency to your impl code, and if so you need to declare
that. If you don't have a compile time dependency, then you have a runtime
dependency and then specify that (scope 'runtime').

If you want different flavors of your webapp, then you create one war
project per "flavor".

/Anders


On Tue, Nov 5, 2013 at 11:50 AM, João Pedro <pe...@gmail.com> wrote:

> I have a multi-module maven project structured in something like this:
>
> parent
>    |
>    |-presentation
>    |+services
>    |    |-services-api
>    |    |-services-impl
>    |+data-access
>    |    |-data-access-api
>    |    |-data-access-impl
>    |-+connector
>    |    |-connector-api
>    |    |-connector-implA
>    |    |-connector-implB
>    |-...
>
> The presentation module is packaged in a war and it depends only on the api
> modules.
>
> When i run the install goal the only dependencies that the war installs are
> the api modules. To choose wich impl modules to install in the presentation
> module i'm using profiles that add the dependency to the impl modules at
> build time depending on the profiles selected.
>
> From what i've been reading i don't think that this is correct usage for
> the maven profiles.
>
> What is the best way to tell maven to add the chosen impl to the
> presentation module?
>
>
> I would like to keep the dependency to only the api module but with the
> usage of profiles, if the profile is active, the dependency is there and no
> compilation errors will happen when i reference a class of the impl
> module...
> thanks
> --
> Cumprimentos,
> João Pedro
>