You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Simone Gianni <si...@apache.org> on 2008/10/05 18:47:16 UTC

Conditional dependencies

Hi all,
I would like to include or exclude a dependency based on the presence of
an artifact on the global class path.

For example, I have a database project. The user will include a
dependency on it in his own pom. The user will also add a JDBC driver
artifact. My database project should be able to declare additional
dependencies depending on the presence of specific JDBC drivers
artifacts, for example a database-mysql-dialect if the mysql-connector
is used, or the database-postgres-dialect if the postgres driver is used.

Whle it is possible to check at runtime, using reflection and the like,
the presence of a given class, it lacks versioning, it is not a clean
way, it clutters the main package code with stuff that could (and
should) be placed in different artifacts.

I don't know any way to do this in Maven right now. Theoretically, it
could be achieved with profile activation, if there was a profile
activation based on the presence of an artifact or at least on the
presence of classpath resources instead of plain files. Is it possible
to implement such a profile activator? Has anybody ever done something
like this? Has anybody had the same need and investigated a way to solve it?

Thanks in advance,
Simone

-- 
Simone Gianni            CEO Semeru s.r.l.           Apache Committer
MALE human being programming a computer   http://www.simonegianni.it/


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


Re: Conditional dependencies

Posted by Simone Gianni <si...@apache.org>.
Hi Michael,
thanks a lot for your answer.

This is how we are currently doing it. In reality our scenario is a bit
more complicated than the given database example. We have many artifacts
(like A and B), and a whole lot of "connection" parts (like A2B), that
would be better placed in their own artifacts, provided that they are
used when both artifacts are in the classpath, and we don't want to have
the user bother with these connection artifacts. Also because A and B
could arrive in the classpath via transiitive dependencies, so the user
have no idea (if not doing a dependency:tree) that they are there and
the connection part A2B is missing.

As a last resort, do you think a plugin can handle these "dynamic"
dependencies? Can a plugin add dependencies to the project, and then
have them resolved and used in the rest of the build lifecycle? Maybe
binding to one of the early phases?

Simone

Michael McCallum wrote:
> wrap the dependency for the db driver in a pom project that also depends upon 
> the dialect
>
> e.g.
>
> example.company.db.posgresql
> -> postgresql jdc driver
> -> postgresql database dialect
>
> then
>
> example.company.applicationwithdb
> -> example.company.db.postgresql
>
> profiles should not be used to munge up dependencies, it just makes it 
> confusing for people to have side effects.
>
> On Mon, 06 Oct 2008 05:47:16 Simone Gianni wrote:
>   
>> Has anybody ever done something
>> like this? Has anybody had the same need and investigated a way to solve
>> it?
>>     
>
>
>
>   


-- 
Simone Gianni            CEO Semeru s.r.l.           Apache Committer
MALE human being programming a computer   http://www.simonegianni.it/


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


Re: Conditional dependencies

Posted by Michael McCallum <gh...@apache.org>.
wrap the dependency for the db driver in a pom project that also depends upon 
the dialect

e.g.

example.company.db.posgresql
-> postgresql jdc driver
-> postgresql database dialect

then

example.company.applicationwithdb
-> example.company.db.postgresql

profiles should not be used to munge up dependencies, it just makes it 
confusing for people to have side effects.

On Mon, 06 Oct 2008 05:47:16 Simone Gianni wrote:
> Has anybody ever done something
> like this? Has anybody had the same need and investigated a way to solve
> it?



-- 
Michael McCallum
Enterprise Engineer
mailto:gholam@apache.org

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