You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by TenLeftFingers <ja...@gmail.com> on 2013/08/13 16:19:15 UTC

Does each maven goal have it's own classpath?

Reading the Sonatype tutorial at
http://books.sonatype.com/mvnex-book/reference/simple-project-sect-simple-core.html
I see this:

  Maven also provides for different dependency scopes. The simple project’s
pom.xml contains a single           
  dependency—junit:junit:jar:3.8.1+—with a scope of +test. When a dependency
has a scope of test, it will 
  not   be available to the compile goal of the Compiler plugin. It will be
added to the classpath for only the   
  compiler:testCompile and surefire:test goals.

This implies that each plugin goal can have it's own classpath. Is this
correct?

Thanks & regards,
Jarlath



--
View this message in context: http://maven.40175.n5.nabble.com/Does-each-maven-goal-have-it-s-own-classpath-tp5767577.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: Does each maven goal have it's own classpath?

Posted by TenLeftFingers <ja...@gmail.com>.
Thanks Stephen Connolly, I need to look into scope a bit more to interpret
your answer better, but I get the gist of it and you've unblocked me from
continuing with the tutorial - thank you.



--
View this message in context: http://maven.40175.n5.nabble.com/Does-each-maven-goal-have-it-s-own-classpath-tp5767577p5767629.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: Does each maven goal have it's own classpath?

Posted by Stephen Connolly <st...@gmail.com>.
Ok, here is the mindf?ck...

The strict answer to your exact question as worded (not the one you are
trying to ask) is:

yes, each mojo (a.k.a. plugin goal) invoked gets it's own classpath
consisting of the core Maven classpath plus the dependencies of the plugin
that declares the mojo.

But that is not the answer to the question you think you asked...

Each mojo can request the list of dependencies of the project and can
filter those dependencies based on the specified scopes of those
dependencies.

So a mojo can say, give me the list of dependencies and filter out so that
only those that make sense for the scope=runtime are retained.

The mojo can then construct a classpath from that list of dependencies.

Now one issue that a mojo may encounter is that the dependencies in the
list may not be resolved yet. This is usually addressed by the mojo being
flagged as requiring dependency resolution. It will usually include a
scope. A mojo may say it requires dependency resolution of scope = compile
but at runtime take the list of dependencies that are filtered with scope =
runtime. This could lead to issues if the mojo is not coded to take
additional defensive measures... by and large, mojo authors do not want to
take that responsibility on themselves, so typically
requiresDependencyResolution is a strong indicator of the scope that the
mojo is interested in.

As there are only 4 main scopes (we will ignore `system` and `import`)
there are thus at most 4 distinct classpaths that a mojo can construct
(without taking additional information from the mojo configuration into
account)... so for mojo's designed to operate on Java projects, there are
effectively at most 4 classpaths that a mojo can pick from... so that would
be a semi-qualified no to the answer you think you were asking.

Hopefully the above will lead you to ask some more questions of yourself
and get you towards enlightenment

-Stephen


On 13 August 2013 15:19, TenLeftFingers <ja...@gmail.com> wrote:

> Reading the Sonatype tutorial at
>
> http://books.sonatype.com/mvnex-book/reference/simple-project-sect-simple-core.html
> I see this:
>
>   Maven also provides for different dependency scopes. The simple project’s
> pom.xml contains a single
>   dependency—junit:junit:jar:3.8.1+—with a scope of +test. When a
> dependency
> has a scope of test, it will
>   not   be available to the compile goal of the Compiler plugin. It will be
> added to the classpath for only the
>   compiler:testCompile and surefire:test goals.
>
> This implies that each plugin goal can have it's own classpath. Is this
> correct?
>
> Thanks & regards,
> Jarlath
>
>
>
> --
> View this message in context:
> http://maven.40175.n5.nabble.com/Does-each-maven-goal-have-it-s-own-classpath-tp5767577.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
>
>