You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Rusty Wright <ru...@gmail.com> on 2009/03/19 01:20:51 UTC

Re: compile-time only depend - how to reference without generating transitive dependency?

Do the imports only have an effect at compile time?  For example, if you have

  package impl.zzz;

  import api.yyy.Yyy;

  public class Xyz implements Yyy {
  }

When you run the app the jvm won't need to have the yyy.Yyy class available?

Even if that's true it seems dubious to me because it seems to me that that means your code is always referring to the concrete class Xyz when it should be using the interface Yyy.  For example, how could you do

   Yyy y = new Xyz();

Would that run without the interface class on the classpath?


sebb wrote:
> On 18/03/2009, sebb <se...@gmail.com> wrote:
>> AIUI, "compile" scope means compile, test and run, and generates a
>>  transitive dependency.
>>
>>  There are some dependencies that are compile-time only, for example
>>  annotations, and Java specification jars - i.e. API-only jars that
>>  have no implementation.
>>
>>  What is the best way to define such a dependency?
>>
>>  The Maven site suggests using "provided", but this does not solve the problem.
>>
>>  Maybe there should be a"compile-only" scope?
>>
> 
> Note that in the case of annotation jars, these are not needed at run-time.
> 
> In the case of API-only jars, at run-time one would use a different
> jar which has the full implementation. This is useful for public specs
> which might not have open source implementations. The API-only jars
> allow one to compile.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 

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


Re: compile-time only depend - how to reference without generating transitive dependency?

Posted by Stuart McCulloch <mc...@gmail.com>.
2009/3/21 sebb <se...@gmail.com>

> On 20/03/2009, Stuart McCulloch <mc...@gmail.com> wrote:
> > 2009/3/20 sebb <se...@gmail.com>
> >
> >
> >  > On 19/03/2009, Stephen Connolly <st...@gmail.com>
> wrote:
> >  >
> >
> > > >  (Note: <optional>true</optional> should have the same effect but I
> have
> >  > >  never quite got that to work the way it should)
> >  > >
> >  >
> >  > I'm told it doesn't, because the dpendency still ends up in OSGI
> bundles.
> >  >
> >
> >
> > FYI, if you're talking about the maven-bundle-plugin then yes, optional
> >  dependencies are added by default but you can choose to ignore them:
> >
> >
> >
> http://cwiki.apache.org/confluence/display/FELIX/Apache+Felix+Maven+Bundle+Plugin+(BND)<http://cwiki.apache.org/confluence/display/FELIX/Apache+Felix+Maven+Bundle+Plugin+%28BND%29>
> >
> >  see the "excludeDependencies" configuration option, for example:
> >
> >   <plugin>
> >     <groupId>org.apache.felix</groupId>
> >     <artifactId>maven-bundle-plugin</artifactId>
> >     <version>2.0.0</version>
> >     <extensions>true</extensions>
> >     <configuration>
> >       <excludeDependencies>*;optional=true</excludeDependencies>
> >       <instructions>
> >         <!-- etc -->
> >       </instructions>
> >     </configuration>
> >   </plugin>
> >
> >  or change the <Embed-Dependency> instruction if you're embedding them
> >
> >  HTH
>
> Thanks!
>
> Seems strange that the default is to include optional dependencies.
>

well when you're wrapping a glob of code into a bundle it can be useful,
otherwise you have to remember to explicitly add optional dependencies
or you may end up with a non-working or (more likely) non-useful bundle

so it just happened that most people expected optional dependencies to
be included by default, and of course once it becomes expected it's hard
to change it later ;)

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

-- 
Cheers, Stuart

Re: compile-time only depend - how to reference without generating transitive dependency?

Posted by sebb <se...@gmail.com>.
On 20/03/2009, Stuart McCulloch <mc...@gmail.com> wrote:
> 2009/3/20 sebb <se...@gmail.com>
>
>
>  > On 19/03/2009, Stephen Connolly <st...@gmail.com> wrote:
>  >
>
> > >  (Note: <optional>true</optional> should have the same effect but I have
>  > >  never quite got that to work the way it should)
>  > >
>  >
>  > I'm told it doesn't, because the dpendency still ends up in OSGI bundles.
>  >
>
>
> FYI, if you're talking about the maven-bundle-plugin then yes, optional
>  dependencies are added by default but you can choose to ignore them:
>
>
>  http://cwiki.apache.org/confluence/display/FELIX/Apache+Felix+Maven+Bundle+Plugin+(BND)
>
>  see the "excludeDependencies" configuration option, for example:
>
>   <plugin>
>     <groupId>org.apache.felix</groupId>
>     <artifactId>maven-bundle-plugin</artifactId>
>     <version>2.0.0</version>
>     <extensions>true</extensions>
>     <configuration>
>       <excludeDependencies>*;optional=true</excludeDependencies>
>       <instructions>
>         <!-- etc -->
>       </instructions>
>     </configuration>
>   </plugin>
>
>  or change the <Embed-Dependency> instruction if you're embedding them
>
>  HTH

Thanks!

Seems strange that the default is to include optional dependencies.

>  >
>  > >  -Stephen
>  > >
>  >
>
> --
>  Cheers, Stuart
>

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


Re: compile-time only depend - how to reference without generating transitive dependency?

Posted by Stuart McCulloch <mc...@gmail.com>.
2009/3/20 sebb <se...@gmail.com>

> On 19/03/2009, Stephen Connolly <st...@gmail.com> wrote:
>
> >  (Note: <optional>true</optional> should have the same effect but I have
> >  never quite got that to work the way it should)
> >
>
> I'm told it doesn't, because the dpendency still ends up in OSGI bundles.
>

FYI, if you're talking about the maven-bundle-plugin then yes, optional
dependencies are added by default but you can choose to ignore them:


http://cwiki.apache.org/confluence/display/FELIX/Apache+Felix+Maven+Bundle+Plugin+(BND)

see the "excludeDependencies" configuration option, for example:

  <plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <version>2.0.0</version>
    <extensions>true</extensions>
    <configuration>
      <excludeDependencies>*;optional=true</excludeDependencies>
      <instructions>
        <!-- etc -->
      </instructions>
    </configuration>
  </plugin>

or change the <Embed-Dependency> instruction if you're embedding them

HTH

>
> >  -Stephen
> >
>
-- 
Cheers, Stuart

Re: compile-time only depend - how to reference without generating transitive dependency?

Posted by sebb <se...@gmail.com>.
On 19/03/2009, Stephen Connolly <st...@gmail.com> wrote:
> 2009/3/19 sebb <se...@gmail.com>
>
>  > On 19/03/2009, Stephen Connolly <st...@gmail.com> wrote:
>  > > 2009/3/19 sebb <se...@gmail.com>
>  > >
>  > >  > On 19/03/2009, Stephen Connolly <st...@gmail.com>
>  > wrote:
>  > >  > > 2009/3/19 sebb <se...@gmail.com>
>  > >  > >
>  > >  > >
>
> > >  > >  > Can I get back to my original question, which is:
>  > >  > >  >
>  > >  > >  > How does one express a dependency on a jar which is only needed
>  > at
>  > >  > >  > compile time, such that the dependency is not propagated?
>  > >  > >  >
>  > >  > >
>  > >  > >
>  > >  > > scope provided will do what you need afaik
>  > >  > >
>  > >  >
>  > >  > Yes, but then AFAIK the user has to download and install the jar

This was an incorrect assumption, see below.

>  > >  > separately, which is a pain.
>  > >  >
>  > >
>  > >
>  > > Nope....
>  >
>  > I think you meant "Yep..." as you seem to be agreeing with me.
>  >
>
>
> I meant Nope... as I was disagreeing with you
>
>
>  >
>  > >  provided just says that somebody will provide it for you and that maven
>  > does
>  > >  not need to worry about it.
>  > >

I understood that to mean that Maven would *not* resolve the
dependency from the repo at build time - which is why I thought you
agreed with me.

But see below - that was a misunderstanding.

>  >
>
>
> provided says that the final deployment location of the jar will have
>  whatever classes are needed at runtime to fullfil this jar's requirements.
>
>  The classes in the jar with provided scope should be on maven's compile and
>  test classpaths for this module... this jar is not needed for any transitive
>  dependencies.

That use of "should" confused me, see below.

>
>  >
>  > Yes, I know.
>  >
>  > Maven maybe does not have to worry about it, but the user does, which
>  > is what I want to avoid.
>  >

Again, this is because I thought Maven did not resolve provided jars
from the repo at build time.

>
>
> IF you are certain that annotations with runtime retention do not break
>  classloading, then you are fine.  Use scope "provided" problem solved.

My bad.

I misunderstood the "provided" scope to mean that something outside
Maven - i.e. the user in this case - has to provide the jar at build
time.

That view appeared to be confirmed by what you wrote (and the Maven
docs), but I see now that I can read it differently.

I've now know that Maven resolves "provided" dependencies from the repository.

Sorry for the noise.

>
>  >
>  > AIUI "provided" is mainly intended for jars that are not available via
>  > the repository, e.g. they may be commercial jars that have to be paid
>  > for separately.
>  >
>
>
> Nope, provided is for artifacts that are either provided in another form by
>  the container in which the jar will run, or are not actually needed.

This is true only of run-time.

See above, I thought it applied to Maven compilations as well.

>  (Note: <optional>true</optional> should have the same effect but I have
>  never quite got that to work the way it should)
>

I'm told it doesn't, because the dpendency still ends up in OSGI bundles.

>
>  -Stephen
>

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


Re: compile-time only depend - how to reference without generating transitive dependency?

Posted by Stephen Connolly <st...@gmail.com>.
2009/3/19 sebb <se...@gmail.com>

> On 19/03/2009, Stephen Connolly <st...@gmail.com> wrote:
> > 2009/3/19 sebb <se...@gmail.com>
> >
> >  > On 19/03/2009, Stephen Connolly <st...@gmail.com>
> wrote:
> >  > > 2009/3/19 sebb <se...@gmail.com>
> >  > >
> >  > >
> >  > >  > Can I get back to my original question, which is:
> >  > >  >
> >  > >  > How does one express a dependency on a jar which is only needed
> at
> >  > >  > compile time, such that the dependency is not propagated?
> >  > >  >
> >  > >
> >  > >
> >  > > scope provided will do what you need afaik
> >  > >
> >  >
> >  > Yes, but then AFAIK the user has to download and install the jar
> >  > separately, which is a pain.
> >  >
> >
> >
> > Nope....
>
> I think you meant "Yep..." as you seem to be agreeing with me.
>

I meant Nope... as I was disagreeing with you

>
> >  provided just says that somebody will provide it for you and that maven
> does
> >  not need to worry about it.
> >
>

provided says that the final deployment location of the jar will have
whatever classes are needed at runtime to fullfil this jar's requirements.

The classes in the jar with provided scope should be on maven's compile and
test classpaths for this module... this jar is not needed for any transitive
dependencies.

>
> Yes, I know.
>
> Maven maybe does not have to worry about it, but the user does, which
> is what I want to avoid.
>

IF you are certain that annotations with runtime retention do not break
classloading, then you are fine.  Use scope "provided" problem solved.


>
> AIUI "provided" is mainly intended for jars that are not available via
> the repository, e.g. they may be commercial jars that have to be paid
> for separately.
>

Nope, provided is for artifacts that are either provided in another form by
the container in which the jar will run, or are not actually needed.

(Note: <optional>true</optional> should have the same effect but I have
never quite got that to work the way it should)


-Stephen

Re: compile-time only depend - how to reference without generating transitive dependency?

Posted by sebb <se...@gmail.com>.
On 19/03/2009, Dev at weitling <de...@weitling.net> wrote:
>
>
>  sebb wrote:
>  > On 19/03/2009, Stephen Connolly <st...@gmail.com> wrote:
>
> >>  > > scope provided will do what you need afaik
>  >>  > >
>  >>  >
>  >>  > Yes, but then AFAIK the user has to download and install the jar
>  >>  > separately, which is a pain.
>  >>  >
>  >>
>  >>
>  >> Nope....
>  >>
>  >
>  > I think you meant "Yep..." as you seem to be agreeing with me.
>  >
>  >
>  >>  provided just says that somebody will provide it for you and that maven does
>  >>  not need to worry about it.
>  >>
>  >
>  > Yes, I know.
>  >
>  > Maven maybe does not have to worry about it, but the user does, which
>  > is what I want to avoid.
>  >
>  > AIUI "provided" is mainly intended for jars that are not available via
>  > the repository, e.g. they may be commercial jars that have to be paid
>  > for separately.
>  >
>
>
> A common examples are servlets: You compile them using the Servlet-API,
>  the runtime jars are provided by the Servlet-container (Tomcat, Jetty...).
>  So your dependency is on Servlet-API wth <scope>provided</scope>.
>
>  Regarding an older post from you: It is (afaik) not possible to load and
>  instantiate a class when its parent classes/interfaces are not
>  loaded/loadable (i.e. on the classpath).

Not my post.

>  Can you deploy your product to the user via Maven?

Not applicable.

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

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


Re: compile-time only depend - how to reference without generating transitive dependency?

Posted by Dev at weitling <de...@weitling.net>.

sebb wrote:
> On 19/03/2009, Stephen Connolly <st...@gmail.com> wrote:
>>  > > scope provided will do what you need afaik
>>  > >
>>  >
>>  > Yes, but then AFAIK the user has to download and install the jar
>>  > separately, which is a pain.
>>  >
>>
>>
>> Nope....
>>     
>
> I think you meant "Yep..." as you seem to be agreeing with me.
>
>   
>>  provided just says that somebody will provide it for you and that maven does
>>  not need to worry about it.
>>     
>
> Yes, I know.
>
> Maven maybe does not have to worry about it, but the user does, which
> is what I want to avoid.
>
> AIUI "provided" is mainly intended for jars that are not available via
> the repository, e.g. they may be commercial jars that have to be paid
> for separately.
>   

A common examples are servlets: You compile them using the Servlet-API,
the runtime jars are provided by the Servlet-container (Tomcat, Jetty...).
So your dependency is on Servlet-API wth <scope>provided</scope>.

Regarding an older post from you: It is (afaik) not possible to load and
instantiate a class when its parent classes/interfaces are not
loaded/loadable (i.e. on the classpath).

Can you deploy your product to the user via Maven?

Regards,
Florian

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


Re: compile-time only depend - how to reference without generating transitive dependency?

Posted by sebb <se...@gmail.com>.
On 19/03/2009, Stephen Connolly <st...@gmail.com> wrote:
> 2009/3/19 sebb <se...@gmail.com>
>
>  > On 19/03/2009, Stephen Connolly <st...@gmail.com> wrote:
>  > > 2009/3/19 sebb <se...@gmail.com>
>  > >
>  > >
>  > >  > On 19/03/2009, Rusty Wright <ru...@gmail.com> wrote:
>  > >  > > Do the imports only have an effect at compile time?  For example, if
>  > you
>  > >  > > have
>  > >  > >
>  > >  > >   package impl.zzz;
>  > >  > >
>  > >  > >   import api.yyy.Yyy;
>  > >  > >
>  > >  > >   public class Xyz implements Yyy {
>  > >  > >   }
>  > >  > >
>  > >  > >  When you run the app the jvm won't need to have the yyy.Yyy class
>  > >  > > available?
>  > >  >
>  > >  > Yes, that's what I wrote.
>  > >  >
>  > >  > At runtime:
>  > >  > - annotation jars are not needed
>  > >
>  > >
>  > >
>  > > Only if they have a retention of compile.... if they are retained at
>  > runtime
>  > >  you'll need them on the classpath
>  > >
>  > >
>  > >
>  > >  >
>  > >  > - code jars are needed, but they may be different from the ones used
>  > to
>  > >  > compile.
>  > >  >
>  > >  > Can I get back to my original question, which is:
>  > >  >
>  > >  > How does one express a dependency on a jar which is only needed at
>  > >  > compile time, such that the dependency is not propagated?
>  > >  >
>  > >
>  > >
>  > > scope provided will do what you need afaik
>  > >
>  >
>  > Yes, but then AFAIK the user has to download and install the jar
>  > separately, which is a pain.
>  >
>
>
> Nope....

I think you meant "Yep..." as you seem to be agreeing with me.

>  provided just says that somebody will provide it for you and that maven does
>  not need to worry about it.
>

Yes, I know.

Maven maybe does not have to worry about it, but the user does, which
is what I want to avoid.

AIUI "provided" is mainly intended for jars that are not available via
the repository, e.g. they may be commercial jars that have to be paid
for separately.

>
>  >
>  > >
>  > >  >
>  > >  > >  Even if that's true it seems dubious to me because it seems to me
>  > that
>  > >  > that
>  > >  > > means your code is always referring to the concrete class Xyz when
>  > it
>  > >  > should
>  > >  > > be using the interface Yyy.  For example, how could you do
>  > >  > >
>  > >  > >   Yyy y = new Xyz();
>  > >  > >
>  > >  > >  Would that run without the interface class on the classpath?
>  > >  > >
>  > >  > >
>  > >  > >  sebb wrote:
>  > >  > >
>  > >  > > >
>  > >  > > > On 18/03/2009, sebb <se...@gmail.com> wrote:
>  > >  > > >
>  > >  > > > > AIUI, "compile" scope means compile, test and run, and generates
>  > a
>  > >  > > > >  transitive dependency.
>  > >  > > > >
>  > >  > > > >  There are some dependencies that are compile-time only, for
>  > example
>  > >  > > > >  annotations, and Java specification jars - i.e. API-only jars
>  > that
>  > >  > > > >  have no implementation.
>  > >  > > > >
>  > >  > > > >  What is the best way to define such a dependency?
>  > >  > > > >
>  > >  > > > >  The Maven site suggests using "provided", but this does not
>  > solve
>  > >  > the
>  > >  > > problem.
>  > >  > > > >
>  > >  > > > >  Maybe there should be a"compile-only" scope?
>  > >  > > > >
>  > >  > > > >
>  > >  > > >
>  > >  > > > Note that in the case of annotation jars, these are not needed at
>  > >  > > run-time.
>  > >  > > >
>  > >  > > > In the case of API-only jars, at run-time one would use a
>  > different
>  > >  > > > jar which has the full implementation. This is useful for public
>  > specs
>  > >  > > > which might not have open source implementations. The API-only
>  > jars
>  > >  > > > allow one to compile.
>  > >  > > >
>  > >  > > >
>  > >  > >
>  > ---------------------------------------------------------------------
>  > >  > > > To unsubscribe, e-mail:
>  > >  > > users-unsubscribe@maven.apache.org
>  > >  > > > For additional commands, e-mail: users-help@maven.apache.org
>  > >  > > >
>  > >  > > >
>  > >  > >
>  > >  > >
>  > ---------------------------------------------------------------------
>  > >  > >  To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>  > >  > >  For additional commands, e-mail: users-help@maven.apache.org
>  > >  > >
>  > >  > >
>  > >  >
>  > >  > ---------------------------------------------------------------------
>  > >  > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>  > >  > For additional commands, e-mail: users-help@maven.apache.org
>  > >  >
>  > >  >
>  > >
>  >
>  > ---------------------------------------------------------------------
>  > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>  > For additional commands, e-mail: users-help@maven.apache.org
>  >
>  >
>

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


Re: compile-time only depend - how to reference without generating transitive dependency?

Posted by Stephen Connolly <st...@gmail.com>.
2009/3/19 sebb <se...@gmail.com>

> On 19/03/2009, Stephen Connolly <st...@gmail.com> wrote:
> > 2009/3/19 sebb <se...@gmail.com>
> >
> >
> >  > On 19/03/2009, Rusty Wright <ru...@gmail.com> wrote:
> >  > > Do the imports only have an effect at compile time?  For example, if
> you
> >  > > have
> >  > >
> >  > >   package impl.zzz;
> >  > >
> >  > >   import api.yyy.Yyy;
> >  > >
> >  > >   public class Xyz implements Yyy {
> >  > >   }
> >  > >
> >  > >  When you run the app the jvm won't need to have the yyy.Yyy class
> >  > > available?
> >  >
> >  > Yes, that's what I wrote.
> >  >
> >  > At runtime:
> >  > - annotation jars are not needed
> >
> >
> >
> > Only if they have a retention of compile.... if they are retained at
> runtime
> >  you'll need them on the classpath
> >
> >
> >
> >  >
> >  > - code jars are needed, but they may be different from the ones used
> to
> >  > compile.
> >  >
> >  > Can I get back to my original question, which is:
> >  >
> >  > How does one express a dependency on a jar which is only needed at
> >  > compile time, such that the dependency is not propagated?
> >  >
> >
> >
> > scope provided will do what you need afaik
> >
>
> Yes, but then AFAIK the user has to download and install the jar
> separately, which is a pain.
>

Nope....

provided just says that somebody will provide it for you and that maven does
not need to worry about it.


>
> >
> >  >
> >  > >  Even if that's true it seems dubious to me because it seems to me
> that
> >  > that
> >  > > means your code is always referring to the concrete class Xyz when
> it
> >  > should
> >  > > be using the interface Yyy.  For example, how could you do
> >  > >
> >  > >   Yyy y = new Xyz();
> >  > >
> >  > >  Would that run without the interface class on the classpath?
> >  > >
> >  > >
> >  > >  sebb wrote:
> >  > >
> >  > > >
> >  > > > On 18/03/2009, sebb <se...@gmail.com> wrote:
> >  > > >
> >  > > > > AIUI, "compile" scope means compile, test and run, and generates
> a
> >  > > > >  transitive dependency.
> >  > > > >
> >  > > > >  There are some dependencies that are compile-time only, for
> example
> >  > > > >  annotations, and Java specification jars - i.e. API-only jars
> that
> >  > > > >  have no implementation.
> >  > > > >
> >  > > > >  What is the best way to define such a dependency?
> >  > > > >
> >  > > > >  The Maven site suggests using "provided", but this does not
> solve
> >  > the
> >  > > problem.
> >  > > > >
> >  > > > >  Maybe there should be a"compile-only" scope?
> >  > > > >
> >  > > > >
> >  > > >
> >  > > > Note that in the case of annotation jars, these are not needed at
> >  > > run-time.
> >  > > >
> >  > > > In the case of API-only jars, at run-time one would use a
> different
> >  > > > jar which has the full implementation. This is useful for public
> specs
> >  > > > which might not have open source implementations. The API-only
> jars
> >  > > > allow one to compile.
> >  > > >
> >  > > >
> >  > >
> ---------------------------------------------------------------------
> >  > > > To unsubscribe, e-mail:
> >  > > users-unsubscribe@maven.apache.org
> >  > > > For additional commands, e-mail: users-help@maven.apache.org
> >  > > >
> >  > > >
> >  > >
> >  > >
> ---------------------------------------------------------------------
> >  > >  To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> >  > >  For additional commands, e-mail: users-help@maven.apache.org
> >  > >
> >  > >
> >  >
> >  > ---------------------------------------------------------------------
> >  > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> >  > For additional commands, e-mail: users-help@maven.apache.org
> >  >
> >  >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: compile-time only depend - how to reference without generating transitive dependency?

Posted by sebb <se...@gmail.com>.
On 19/03/2009, Stephen Connolly <st...@gmail.com> wrote:
> 2009/3/19 sebb <se...@gmail.com>
>
>
>  > On 19/03/2009, Rusty Wright <ru...@gmail.com> wrote:
>  > > Do the imports only have an effect at compile time?  For example, if you
>  > > have
>  > >
>  > >   package impl.zzz;
>  > >
>  > >   import api.yyy.Yyy;
>  > >
>  > >   public class Xyz implements Yyy {
>  > >   }
>  > >
>  > >  When you run the app the jvm won't need to have the yyy.Yyy class
>  > > available?
>  >
>  > Yes, that's what I wrote.
>  >
>  > At runtime:
>  > - annotation jars are not needed
>
>
>
> Only if they have a retention of compile.... if they are retained at runtime
>  you'll need them on the classpath
>
>
>
>  >
>  > - code jars are needed, but they may be different from the ones used to
>  > compile.
>  >
>  > Can I get back to my original question, which is:
>  >
>  > How does one express a dependency on a jar which is only needed at
>  > compile time, such that the dependency is not propagated?
>  >
>
>
> scope provided will do what you need afaik
>

Yes, but then AFAIK the user has to download and install the jar
separately, which is a pain.

>
>  >
>  > >  Even if that's true it seems dubious to me because it seems to me that
>  > that
>  > > means your code is always referring to the concrete class Xyz when it
>  > should
>  > > be using the interface Yyy.  For example, how could you do
>  > >
>  > >   Yyy y = new Xyz();
>  > >
>  > >  Would that run without the interface class on the classpath?
>  > >
>  > >
>  > >  sebb wrote:
>  > >
>  > > >
>  > > > On 18/03/2009, sebb <se...@gmail.com> wrote:
>  > > >
>  > > > > AIUI, "compile" scope means compile, test and run, and generates a
>  > > > >  transitive dependency.
>  > > > >
>  > > > >  There are some dependencies that are compile-time only, for example
>  > > > >  annotations, and Java specification jars - i.e. API-only jars that
>  > > > >  have no implementation.
>  > > > >
>  > > > >  What is the best way to define such a dependency?
>  > > > >
>  > > > >  The Maven site suggests using "provided", but this does not solve
>  > the
>  > > problem.
>  > > > >
>  > > > >  Maybe there should be a"compile-only" scope?
>  > > > >
>  > > > >
>  > > >
>  > > > Note that in the case of annotation jars, these are not needed at
>  > > run-time.
>  > > >
>  > > > In the case of API-only jars, at run-time one would use a different
>  > > > jar which has the full implementation. This is useful for public specs
>  > > > which might not have open source implementations. The API-only jars
>  > > > allow one to compile.
>  > > >
>  > > >
>  > > ---------------------------------------------------------------------
>  > > > To unsubscribe, e-mail:
>  > > users-unsubscribe@maven.apache.org
>  > > > For additional commands, e-mail: users-help@maven.apache.org
>  > > >
>  > > >
>  > >
>  > > ---------------------------------------------------------------------
>  > >  To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>  > >  For additional commands, e-mail: users-help@maven.apache.org
>  > >
>  > >
>  >
>  > ---------------------------------------------------------------------
>  > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>  > For additional commands, e-mail: users-help@maven.apache.org
>  >
>  >
>

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


Re: compile-time only depend - how to reference without generating transitive dependency?

Posted by Stuart McCulloch <mc...@gmail.com>.
2009/3/19 Stephen Connolly <st...@gmail.com>

> 2009/3/19 sebb <se...@gmail.com>
>
> > On 19/03/2009, Rusty Wright <ru...@gmail.com> wrote:
> > > Do the imports only have an effect at compile time?  For example, if
> you
> > > have
> > >
> > >   package impl.zzz;
> > >
> > >   import api.yyy.Yyy;
> > >
> > >   public class Xyz implements Yyy {
> > >   }
> > >
> > >  When you run the app the jvm won't need to have the yyy.Yyy class
> > > available?
> >
> > Yes, that's what I wrote.
> >
> > At runtime:
> > - annotation jars are not needed
>
> Only if they have a retention of compile.... if they are retained at
> runtime
> you'll need them on the classpath
>

another thing to note about runtime retained annotations is that you can
actually use the annotated class without having the annotation classes on
the runtime classpath - however when you query the class using reflection
you won't be able to see the missing annotations, because the JVM filters
them out as part of the classloading process

this means you can annotate classes with Spring+Guice+EJB annotations
and you'll only need all of these framework jars when compiling the source

when it comes to deployment you just need to pick the framework that you
intend to use, which 'activates' the necessary annotations - the others are
still in the class-file waiting for when you deploy it to another framework

HTH

>
> > - code jars are needed, but they may be different from the ones used to
> > compile.
> >
> > Can I get back to my original question, which is:
> >
> > How does one express a dependency on a jar which is only needed at
> > compile time, such that the dependency is not propagated?
> >
>
> scope provided will do what you need afaik
>
>
> >
> > >  Even if that's true it seems dubious to me because it seems to me that
> > that
> > > means your code is always referring to the concrete class Xyz when it
> > should
> > > be using the interface Yyy.  For example, how could you do
> > >
> > >   Yyy y = new Xyz();
> > >
> > >  Would that run without the interface class on the classpath?
> > >
> > >
> > >  sebb wrote:
> > >
> > > >
> > > > On 18/03/2009, sebb <se...@gmail.com> wrote:
> > > >
> > > > > AIUI, "compile" scope means compile, test and run, and generates a
> > > > >  transitive dependency.
> > > > >
> > > > >  There are some dependencies that are compile-time only, for
> example
> > > > >  annotations, and Java specification jars - i.e. API-only jars that
> > > > >  have no implementation.
> > > > >
> > > > >  What is the best way to define such a dependency?
> > > > >
> > > > >  The Maven site suggests using "provided", but this does not solve
> > the
> > > problem.
> > > > >
> > > > >  Maybe there should be a"compile-only" scope?
> > > > >
> > > > >
> > > >
> > > > Note that in the case of annotation jars, these are not needed at
> > > run-time.
> > > >
> > > > In the case of API-only jars, at run-time one would use a different
> > > > jar which has the full implementation. This is useful for public
> specs
> > > > which might not have open source implementations. The API-only jars
> > > > allow one to compile.
> > > >
> > > >
> > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail:
> > > users-unsubscribe@maven.apache.org
> > > > For additional commands, e-mail: users-help@maven.apache.org
> > > >
> > > >
> > >
> > > ---------------------------------------------------------------------
> > >  To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > >  For additional commands, e-mail: users-help@maven.apache.org
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> >
>



-- 
Cheers, Stuart

Re: compile-time only depend - how to reference without generating transitive dependency?

Posted by Stephen Connolly <st...@gmail.com>.
2009/3/19 sebb <se...@gmail.com>

> On 19/03/2009, Rusty Wright <ru...@gmail.com> wrote:
> > Do the imports only have an effect at compile time?  For example, if you
> > have
> >
> >   package impl.zzz;
> >
> >   import api.yyy.Yyy;
> >
> >   public class Xyz implements Yyy {
> >   }
> >
> >  When you run the app the jvm won't need to have the yyy.Yyy class
> > available?
>
> Yes, that's what I wrote.
>
> At runtime:
> - annotation jars are not needed


Only if they have a retention of compile.... if they are retained at runtime
you'll need them on the classpath


>
> - code jars are needed, but they may be different from the ones used to
> compile.
>
> Can I get back to my original question, which is:
>
> How does one express a dependency on a jar which is only needed at
> compile time, such that the dependency is not propagated?
>

scope provided will do what you need afaik


>
> >  Even if that's true it seems dubious to me because it seems to me that
> that
> > means your code is always referring to the concrete class Xyz when it
> should
> > be using the interface Yyy.  For example, how could you do
> >
> >   Yyy y = new Xyz();
> >
> >  Would that run without the interface class on the classpath?
> >
> >
> >  sebb wrote:
> >
> > >
> > > On 18/03/2009, sebb <se...@gmail.com> wrote:
> > >
> > > > AIUI, "compile" scope means compile, test and run, and generates a
> > > >  transitive dependency.
> > > >
> > > >  There are some dependencies that are compile-time only, for example
> > > >  annotations, and Java specification jars - i.e. API-only jars that
> > > >  have no implementation.
> > > >
> > > >  What is the best way to define such a dependency?
> > > >
> > > >  The Maven site suggests using "provided", but this does not solve
> the
> > problem.
> > > >
> > > >  Maybe there should be a"compile-only" scope?
> > > >
> > > >
> > >
> > > Note that in the case of annotation jars, these are not needed at
> > run-time.
> > >
> > > In the case of API-only jars, at run-time one would use a different
> > > jar which has the full implementation. This is useful for public specs
> > > which might not have open source implementations. The API-only jars
> > > allow one to compile.
> > >
> > >
> > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > users-unsubscribe@maven.apache.org
> > > For additional commands, e-mail: users-help@maven.apache.org
> > >
> > >
> >
> > ---------------------------------------------------------------------
> >  To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> >  For additional commands, e-mail: users-help@maven.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: compile-time only depend - how to reference without generating transitive dependency?

Posted by Stuart McCulloch <mc...@gmail.com>.
On 19 Mar 2009, at 09:19, sebb <se...@gmail.com> wrote:

> On 19/03/2009, Rusty Wright <ru...@gmail.com> wrote:
>> Do the imports only have an effect at compile time?  For example,  
>> if you
>> have
>>
>>  package impl.zzz;
>>
>>  import api.yyy.Yyy;
>>
>>  public class Xyz implements Yyy {
>>  }
>>
>> When you run the app the jvm won't need to have the yyy.Yyy class
>> available?
>
> Yes, that's what I wrote.
>
> At runtime:
> - annotation jars are not needed
> - code jars are needed, but they may be different from the ones used  
> to compile.
>
> Can I get back to my original question, which is:
>
> How does one express a dependency on a jar which is only needed at
> compile time, such that the dependency is not propagated?

Mark it as <optional>true</optional> ?

Optional dependencies appear on the compilation classpath but afaik  
won't be propagated to dependent projects..

>> Even if that's true it seems dubious to me because it seems to me  
>> that that
>> means your code is always referring to the concrete class Xyz when  
>> it should
>> be using the interface Yyy.  For example, how could you do
>>
>>  Yyy y = new Xyz();
>>
>> Would that run without the interface class on the classpath?
>>
>>
>> sebb wrote:
>>
>>>
>>> On 18/03/2009, sebb <se...@gmail.com> wrote:
>>>
>>>> AIUI, "compile" scope means compile, test and run, and generates a
>>>> transitive dependency.
>>>>
>>>> There are some dependencies that are compile-time only, for example
>>>> annotations, and Java specification jars - i.e. API-only jars that
>>>> have no implementation.
>>>>
>>>> What is the best way to define such a dependency?
>>>>
>>>> The Maven site suggests using "provided", but this does not solve  
>>>> the
>> problem.
>>>>
>>>> Maybe there should be a"compile-only" scope?
>>>>
>>>>
>>>
>>> Note that in the case of annotation jars, these are not needed at
>> run-time.
>>>
>>> In the case of API-only jars, at run-time one would use a different
>>> jar which has the full implementation. This is useful for public  
>>> specs
>>> which might not have open source implementations. The API-only jars
>>> allow one to compile.
>>>
>>>
>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail:
>> users-unsubscribe@maven.apache.org
>>> For additional commands, e-mail: users-help@maven.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>

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


Re: compile-time only depend - how to reference without generating transitive dependency?

Posted by sebb <se...@gmail.com>.
On 19/03/2009, Rusty Wright <ru...@gmail.com> wrote:
> Do the imports only have an effect at compile time?  For example, if you
> have
>
>   package impl.zzz;
>
>   import api.yyy.Yyy;
>
>   public class Xyz implements Yyy {
>   }
>
>  When you run the app the jvm won't need to have the yyy.Yyy class
> available?

Yes, that's what I wrote.

At runtime:
- annotation jars are not needed
- code jars are needed, but they may be different from the ones used to compile.

Can I get back to my original question, which is:

How does one express a dependency on a jar which is only needed at
compile time, such that the dependency is not propagated?

>  Even if that's true it seems dubious to me because it seems to me that that
> means your code is always referring to the concrete class Xyz when it should
> be using the interface Yyy.  For example, how could you do
>
>   Yyy y = new Xyz();
>
>  Would that run without the interface class on the classpath?
>
>
>  sebb wrote:
>
> >
> > On 18/03/2009, sebb <se...@gmail.com> wrote:
> >
> > > AIUI, "compile" scope means compile, test and run, and generates a
> > >  transitive dependency.
> > >
> > >  There are some dependencies that are compile-time only, for example
> > >  annotations, and Java specification jars - i.e. API-only jars that
> > >  have no implementation.
> > >
> > >  What is the best way to define such a dependency?
> > >
> > >  The Maven site suggests using "provided", but this does not solve the
> problem.
> > >
> > >  Maybe there should be a"compile-only" scope?
> > >
> > >
> >
> > Note that in the case of annotation jars, these are not needed at
> run-time.
> >
> > In the case of API-only jars, at run-time one would use a different
> > jar which has the full implementation. This is useful for public specs
> > which might not have open source implementations. The API-only jars
> > allow one to compile.
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> >
>
> ---------------------------------------------------------------------
>  To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>  For additional commands, e-mail: users-help@maven.apache.org
>
>

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