You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by "Plotnicki, Grzegorz " <gr...@citi.com> on 2007/11/05 19:17:28 UTC

Build.setSourceDirectory() & MavenProject.getCompileSourceRoots()

Hi,

I'm writing a custom plug-in and want to change the standard location of
a source directory + add additional source directories. I've used
Build.setSourceDirectory() at the initialize phase, but when I try
access all the source directories in the compile phase via
MavenProject.getCompileSourceRoots(), it doesn't list the one I set with
Build.setSourceDirectory() and it also keep listing the standard java
dir (src/main/java).

Is it a standard behavior? If so, what's the conceptual difference
between sourceDirectory and compileSourceRoots? Is there a way to
remove/replace the standard java dir in the compileSourceRoots?

thanQ

Grzeg~
=)

...{-_-}...
In a real dark night of the soul 
it is always three o'clock in the morning, day after day.
	-- F. Scott Fitzgerald



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


Re: Build.setSourceDirectory() & MavenProject.getCompileSourceRoots()

Posted by SingleShot <mi...@gmail.com>.
There is a slight chance this may be helpful to you (or anyone interested in
this topic)...

You confirm what I learned from playing around with the Project API - you
cannot override the value of build.setSourceDirectory(). However, you can
override it in the POM via the build/sourceDirectory element. That should
probably be choice #1.

The reason I care about this is that I too was writing a plugin for a tool
that did not fit "the Maven way" at all. I needed to give the tool source
code, which it would compile on its own. Unfortunately, the tool would also
generate source code which I needed to compile myself. Yuck. This means I
needed the plugin to add the generated source to the list of source
directories so the compiler plugin could see it, but I had to somehow tell
the compiler plugin to ignore the "normal" source directory (or else I would
end up with duplicate classes). My solution was to stick my source code in a
directory other than src/main/java (such as src/main/java-for-lame-tool) and
configure my plugin to use that as its source location, and to author the
plugin to add its generated source to the list of source directories.

My situation was a strange one. I could have simply configured the POM's
sourceDirectory to point at my generated source directory, but because of
the way we have structured our modules, I would have had to override that
value in many POMs (our structure prevented using POM inheritance for this).
Rather than increase POM duplication, I opted for an ugly yet workable
solution for an ugly tool.



Plotnicki, Grzegorz wrote:
> 
> Hi,
> 
> I'm writing a custom plug-in and want to change the standard location of
> a source directory + add additional source directories. I've used
> Build.setSourceDirectory() at the initialize phase, but when I try
> access all the source directories in the compile phase via
> MavenProject.getCompileSourceRoots(), it doesn't list the one I set with
> Build.setSourceDirectory() and it also keep listing the standard java
> dir (src/main/java).
> 
> Is it a standard behavior? If so, what's the conceptual difference
> between sourceDirectory and compileSourceRoots? Is there a way to
> remove/replace the standard java dir in the compileSourceRoots?
> 
> thanQ
> 
> Grzeg~
> =)
> 
> ...{-_-}...
> In a real dark night of the soul 
> it is always three o'clock in the morning, day after day.
> 	-- F. Scott Fitzgerald
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Build.setSourceDirectory%28%29---MavenProject.getCompileSourceRoots%28%29-tp13593158s177p16276690.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