Re: writing a maven plugin that transparently adds a new source folder
Just an update on this in case there is anyone else who is interested. I found an answer to this on stackoverflow: http://stackoverflow.com/questions/8389825/creating-a-maven-mojo-that-automatically-adds-new-source-folders-to-the-build On Wed, Nov 30, 2011 at 3:07 PM, Stephen Connolly wrote: > That just defined the default phase that the goal will bind to if you don't > specify a phase... but you need to bind a goal to a phase in the consumer's > pom or the packaging lifecycle > > On 30 November 2011 23:00, Jeff MAURY wrote: > >> This is done through a Javadoc annotation in your Mojo source file. >> >> Regards >> Jeff MAURY >> >> On Wed, Nov 30, 2011 at 11:45 PM, Andrew Eisenberg < >> andrew.eisenb...@gmail.com> wrote: >> >> > Sorry for asking so many questions, but I am now confused. When you >> > say "You must bind your mojo to a specific phase", where does this >> > binding happen? Inside the pom associated with the mojo or inside the >> > plugin consumer's pom? Earlier, I think you implied that this had to >> > happen in the consumer's pom, but is that not what you are saying now? >> > If this is the correct interpretation, can you point me to some docs >> > or an example of how to do this? >> > >> > My goal is to do all of the configuring inside of the mojo's pom so >> > that the plugin consumer has to do as little configuring as possible >> > (preferably none at all, except for declaring a dependency). >> > >> > thanks, >> > Andrew >> > >> > On Wed, Nov 30, 2011 at 2:26 PM, Jeff MAURY >> > wrote: >> > > No, you can have a mojo automatically invoked as soon as it is declared >> > in >> > > a pom. You must bind your mojo to a specific phase. >> > > >> > > Regards >> > > Jeff MAURY >> > > >> > > On Wed, Nov 30, 2011 at 10:48 PM, Andrew Eisenberg < >> > > andrew.eisenb...@gmail.com> wrote: >> > > >> > >> On Wed, Nov 30, 2011 at 1:31 PM, Jeff MAURY >> > >> wrote: >> > >> > You can develop a Mojo that will do the trick but you will have to >> > >> > configure it in you pom (at least define it so that it will be >> > invoked) >> > >> so >> > >> > I don't see the added value compared to the build-helper-plugin >> > >> >> > >> Right. Well, the only benefit is that doing it through the mojo that I >> > >> would create is about 6 fewer lines of configuration, which is not >> > >> much benefit (and I actually did get this working, but I wasn't happy >> > >> with the solution). I must say that I am disappointed in maven that >> > >> this is not possible. I was expecting that mojos could somehow be >> > >> executed implicitly just by referencing a plugin in your pom. I'm >> > >> sure there's a reason for not allowing this, but from my perspective >> > >> allowing this would certainly cut down on some configuration >> > >> verbosity. >> > >> >> > >> Thanks for your help with this. I'll have to settle for the >> > >> build-helper-maven-plugin approach. >> > >> >> > >> - >> > >> To unsubscribe, e-mail: users-unsubscr...@maven.apache.org >> > >> For additional commands, e-mail: users-h...@maven.apache.org >> > >> >> > >> >> > > >> > > >> > > -- >> > > "Legacy code" often differs from its suggested alternative by actually >> > > working and scaling. >> > > - Bjarne Stroustrup >> > > >> > > http://www.jeffmaury.com >> > > http://riadiscuss.jeffmaury.com >> > > http://www.twitter.com/jeffmaury >> > >> > - >> > To unsubscribe, e-mail: users-unsubscr...@maven.apache.org >> > For additional commands, e-mail: users-h...@maven.apache.org >> > >> > >> >> >> -- >> "Legacy code" often differs from its suggested alternative by actually >> working and scaling. >> - Bjarne Stroustrup >> >> http://www.jeffmaury.com >> http://riadiscuss.jeffmaury.com >> http://www.twitter.com/jeffmaury >> - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org
Re: writing a maven plugin that transparently adds a new source folder
That just defined the default phase that the goal will bind to if you don't specify a phase... but you need to bind a goal to a phase in the consumer's pom or the packaging lifecycle On 30 November 2011 23:00, Jeff MAURY wrote: > This is done through a Javadoc annotation in your Mojo source file. > > Regards > Jeff MAURY > > On Wed, Nov 30, 2011 at 11:45 PM, Andrew Eisenberg < > andrew.eisenb...@gmail.com> wrote: > > > Sorry for asking so many questions, but I am now confused. When you > > say "You must bind your mojo to a specific phase", where does this > > binding happen? Inside the pom associated with the mojo or inside the > > plugin consumer's pom? Earlier, I think you implied that this had to > > happen in the consumer's pom, but is that not what you are saying now? > > If this is the correct interpretation, can you point me to some docs > > or an example of how to do this? > > > > My goal is to do all of the configuring inside of the mojo's pom so > > that the plugin consumer has to do as little configuring as possible > > (preferably none at all, except for declaring a dependency). > > > > thanks, > > Andrew > > > > On Wed, Nov 30, 2011 at 2:26 PM, Jeff MAURY > > wrote: > > > No, you can have a mojo automatically invoked as soon as it is declared > > in > > > a pom. You must bind your mojo to a specific phase. > > > > > > Regards > > > Jeff MAURY > > > > > > On Wed, Nov 30, 2011 at 10:48 PM, Andrew Eisenberg < > > > andrew.eisenb...@gmail.com> wrote: > > > > > >> On Wed, Nov 30, 2011 at 1:31 PM, Jeff MAURY > > >> wrote: > > >> > You can develop a Mojo that will do the trick but you will have to > > >> > configure it in you pom (at least define it so that it will be > > invoked) > > >> so > > >> > I don't see the added value compared to the build-helper-plugin > > >> > > >> Right. Well, the only benefit is that doing it through the mojo that I > > >> would create is about 6 fewer lines of configuration, which is not > > >> much benefit (and I actually did get this working, but I wasn't happy > > >> with the solution). I must say that I am disappointed in maven that > > >> this is not possible. I was expecting that mojos could somehow be > > >> executed implicitly just by referencing a plugin in your pom. I'm > > >> sure there's a reason for not allowing this, but from my perspective > > >> allowing this would certainly cut down on some configuration > > >> verbosity. > > >> > > >> Thanks for your help with this. I'll have to settle for the > > >> build-helper-maven-plugin approach. > > >> > > >> - > > >> To unsubscribe, e-mail: users-unsubscr...@maven.apache.org > > >> For additional commands, e-mail: users-h...@maven.apache.org > > >> > > >> > > > > > > > > > -- > > > "Legacy code" often differs from its suggested alternative by actually > > > working and scaling. > > > - Bjarne Stroustrup > > > > > > http://www.jeffmaury.com > > > http://riadiscuss.jeffmaury.com > > > http://www.twitter.com/jeffmaury > > > > - > > To unsubscribe, e-mail: users-unsubscr...@maven.apache.org > > For additional commands, e-mail: users-h...@maven.apache.org > > > > > > > -- > "Legacy code" often differs from its suggested alternative by actually > working and scaling. > - Bjarne Stroustrup > > http://www.jeffmaury.com > http://riadiscuss.jeffmaury.com > http://www.twitter.com/jeffmaury >
Re: writing a maven plugin that transparently adds a new source folder
This is done through a Javadoc annotation in your Mojo source file. Regards Jeff MAURY On Wed, Nov 30, 2011 at 11:45 PM, Andrew Eisenberg < andrew.eisenb...@gmail.com> wrote: > Sorry for asking so many questions, but I am now confused. When you > say "You must bind your mojo to a specific phase", where does this > binding happen? Inside the pom associated with the mojo or inside the > plugin consumer's pom? Earlier, I think you implied that this had to > happen in the consumer's pom, but is that not what you are saying now? > If this is the correct interpretation, can you point me to some docs > or an example of how to do this? > > My goal is to do all of the configuring inside of the mojo's pom so > that the plugin consumer has to do as little configuring as possible > (preferably none at all, except for declaring a dependency). > > thanks, > Andrew > > On Wed, Nov 30, 2011 at 2:26 PM, Jeff MAURY > wrote: > > No, you can have a mojo automatically invoked as soon as it is declared > in > > a pom. You must bind your mojo to a specific phase. > > > > Regards > > Jeff MAURY > > > > On Wed, Nov 30, 2011 at 10:48 PM, Andrew Eisenberg < > > andrew.eisenb...@gmail.com> wrote: > > > >> On Wed, Nov 30, 2011 at 1:31 PM, Jeff MAURY > >> wrote: > >> > You can develop a Mojo that will do the trick but you will have to > >> > configure it in you pom (at least define it so that it will be > invoked) > >> so > >> > I don't see the added value compared to the build-helper-plugin > >> > >> Right. Well, the only benefit is that doing it through the mojo that I > >> would create is about 6 fewer lines of configuration, which is not > >> much benefit (and I actually did get this working, but I wasn't happy > >> with the solution). I must say that I am disappointed in maven that > >> this is not possible. I was expecting that mojos could somehow be > >> executed implicitly just by referencing a plugin in your pom. I'm > >> sure there's a reason for not allowing this, but from my perspective > >> allowing this would certainly cut down on some configuration > >> verbosity. > >> > >> Thanks for your help with this. I'll have to settle for the > >> build-helper-maven-plugin approach. > >> > >> - > >> To unsubscribe, e-mail: users-unsubscr...@maven.apache.org > >> For additional commands, e-mail: users-h...@maven.apache.org > >> > >> > > > > > > -- > > "Legacy code" often differs from its suggested alternative by actually > > working and scaling. > > - Bjarne Stroustrup > > > > http://www.jeffmaury.com > > http://riadiscuss.jeffmaury.com > > http://www.twitter.com/jeffmaury > > - > To unsubscribe, e-mail: users-unsubscr...@maven.apache.org > For additional commands, e-mail: users-h...@maven.apache.org > > -- "Legacy code" often differs from its suggested alternative by actually working and scaling. - Bjarne Stroustrup http://www.jeffmaury.com http://riadiscuss.jeffmaury.com http://www.twitter.com/jeffmaury
Re: writing a maven plugin that transparently adds a new source folder
On 30 November 2011 22:45, Andrew Eisenberg wrote: > Sorry for asking so many questions, but I am now confused. When you > say "You must bind your mojo to a specific phase", where does this > binding happen? Inside the pom associated with the mojo or inside the > plugin consumer's pom? Earlier, I think you implied that this had to > plugin consumer's pom or the definition of the lifecycle for the packaging... the standard packaging's are defined in maven core, to have a non-standard packaging you need to add your packaging as an extension (either through /project/build/extensions or by marking a plugin that contains the lifecycle as containing extensions happen in the consumer's pom, but is that not what you are saying now? > If this is the correct interpretation, can you point me to some docs > or an example of how to do this? > > My goal is to do all of the configuring inside of the mojo's pom so > that the plugin consumer has to do as little configuring as possible > (preferably none at all, except for declaring a dependency). > > thanks, > Andrew > > On Wed, Nov 30, 2011 at 2:26 PM, Jeff MAURY > wrote: > > No, you can have a mojo automatically invoked as soon as it is declared > in > > a pom. You must bind your mojo to a specific phase. > > > > Regards > > Jeff MAURY > > > > On Wed, Nov 30, 2011 at 10:48 PM, Andrew Eisenberg < > > andrew.eisenb...@gmail.com> wrote: > > > >> On Wed, Nov 30, 2011 at 1:31 PM, Jeff MAURY > >> wrote: > >> > You can develop a Mojo that will do the trick but you will have to > >> > configure it in you pom (at least define it so that it will be > invoked) > >> so > >> > I don't see the added value compared to the build-helper-plugin > >> > >> Right. Well, the only benefit is that doing it through the mojo that I > >> would create is about 6 fewer lines of configuration, which is not > >> much benefit (and I actually did get this working, but I wasn't happy > >> with the solution). I must say that I am disappointed in maven that > >> this is not possible. I was expecting that mojos could somehow be > >> executed implicitly just by referencing a plugin in your pom. I'm > >> sure there's a reason for not allowing this, but from my perspective > >> allowing this would certainly cut down on some configuration > >> verbosity. > >> > >> Thanks for your help with this. I'll have to settle for the > >> build-helper-maven-plugin approach. > >> > >> - > >> To unsubscribe, e-mail: users-unsubscr...@maven.apache.org > >> For additional commands, e-mail: users-h...@maven.apache.org > >> > >> > > > > > > -- > > "Legacy code" often differs from its suggested alternative by actually > > working and scaling. > > - Bjarne Stroustrup > > > > http://www.jeffmaury.com > > http://riadiscuss.jeffmaury.com > > http://www.twitter.com/jeffmaury > > - > To unsubscribe, e-mail: users-unsubscr...@maven.apache.org > For additional commands, e-mail: users-h...@maven.apache.org > >
Re: writing a maven plugin that transparently adds a new source folder
Sorry for asking so many questions, but I am now confused. When you say "You must bind your mojo to a specific phase", where does this binding happen? Inside the pom associated with the mojo or inside the plugin consumer's pom? Earlier, I think you implied that this had to happen in the consumer's pom, but is that not what you are saying now? If this is the correct interpretation, can you point me to some docs or an example of how to do this? My goal is to do all of the configuring inside of the mojo's pom so that the plugin consumer has to do as little configuring as possible (preferably none at all, except for declaring a dependency). thanks, Andrew On Wed, Nov 30, 2011 at 2:26 PM, Jeff MAURY wrote: > No, you can have a mojo automatically invoked as soon as it is declared in > a pom. You must bind your mojo to a specific phase. > > Regards > Jeff MAURY > > On Wed, Nov 30, 2011 at 10:48 PM, Andrew Eisenberg < > andrew.eisenb...@gmail.com> wrote: > >> On Wed, Nov 30, 2011 at 1:31 PM, Jeff MAURY >> wrote: >> > You can develop a Mojo that will do the trick but you will have to >> > configure it in you pom (at least define it so that it will be invoked) >> so >> > I don't see the added value compared to the build-helper-plugin >> >> Right. Well, the only benefit is that doing it through the mojo that I >> would create is about 6 fewer lines of configuration, which is not >> much benefit (and I actually did get this working, but I wasn't happy >> with the solution). I must say that I am disappointed in maven that >> this is not possible. I was expecting that mojos could somehow be >> executed implicitly just by referencing a plugin in your pom. I'm >> sure there's a reason for not allowing this, but from my perspective >> allowing this would certainly cut down on some configuration >> verbosity. >> >> Thanks for your help with this. I'll have to settle for the >> build-helper-maven-plugin approach. >> >> - >> To unsubscribe, e-mail: users-unsubscr...@maven.apache.org >> For additional commands, e-mail: users-h...@maven.apache.org >> >> > > > -- > "Legacy code" often differs from its suggested alternative by actually > working and scaling. > - Bjarne Stroustrup > > http://www.jeffmaury.com > http://riadiscuss.jeffmaury.com > http://www.twitter.com/jeffmaury - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org
Re: writing a maven plugin that transparently adds a new source folder
No, you can have a mojo automatically invoked as soon as it is declared in a pom. You must bind your mojo to a specific phase. Regards Jeff MAURY On Wed, Nov 30, 2011 at 10:48 PM, Andrew Eisenberg < andrew.eisenb...@gmail.com> wrote: > On Wed, Nov 30, 2011 at 1:31 PM, Jeff MAURY > wrote: > > You can develop a Mojo that will do the trick but you will have to > > configure it in you pom (at least define it so that it will be invoked) > so > > I don't see the added value compared to the build-helper-plugin > > Right. Well, the only benefit is that doing it through the mojo that I > would create is about 6 fewer lines of configuration, which is not > much benefit (and I actually did get this working, but I wasn't happy > with the solution). I must say that I am disappointed in maven that > this is not possible. I was expecting that mojos could somehow be > executed implicitly just by referencing a plugin in your pom. I'm > sure there's a reason for not allowing this, but from my perspective > allowing this would certainly cut down on some configuration > verbosity. > > Thanks for your help with this. I'll have to settle for the > build-helper-maven-plugin approach. > > - > To unsubscribe, e-mail: users-unsubscr...@maven.apache.org > For additional commands, e-mail: users-h...@maven.apache.org > > -- "Legacy code" often differs from its suggested alternative by actually working and scaling. - Bjarne Stroustrup http://www.jeffmaury.com http://riadiscuss.jeffmaury.com http://www.twitter.com/jeffmaury
Re: writing a maven plugin that transparently adds a new source folder
On Wed, Nov 30, 2011 at 1:31 PM, Jeff MAURY wrote: > You can develop a Mojo that will do the trick but you will have to > configure it in you pom (at least define it so that it will be invoked) so > I don't see the added value compared to the build-helper-plugin Right. Well, the only benefit is that doing it through the mojo that I would create is about 6 fewer lines of configuration, which is not much benefit (and I actually did get this working, but I wasn't happy with the solution). I must say that I am disappointed in maven that this is not possible. I was expecting that mojos could somehow be executed implicitly just by referencing a plugin in your pom. I'm sure there's a reason for not allowing this, but from my perspective allowing this would certainly cut down on some configuration verbosity. Thanks for your help with this. I'll have to settle for the build-helper-maven-plugin approach. - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org
Re: writing a maven plugin that transparently adds a new source folder
You can develop a Mojo that will do the trick but you will have to configure it in you pom (at least define it so that it will be invoked) so I don't see the added value compared to the build-helper-plugin Regards Jeff MAURY On Wed, Nov 30, 2011 at 7:53 PM, Andrew Eisenberg < andrew.eisenb...@gmail.com> wrote: > Thanks, Jeff and Stephen for your answers. I know about the > build-helper-maven-plugin, but this adds about 20 lines of > configuration to the pom and I was hoping to avoid that. Also, > forcing users to specify a parent pom is not feasible since users will > likely have their own parent poms to use. > > My goal is to simplify the configuration of the pom so that with just > about 3-4 lines of configuration, all the functionality happens > automatically. Are you suggesting that this is not possible? > > ps- Apologies for not responding sooner, but somehow these messages > have been ending up in my spam folder. > > On Sat, Nov 26, 2011 at 9:59 AM, Jeff MAURY > wrote: > > If you need to add source folders, there is an existing Maven plugin to > do > > it: the build-helper-maven-plugin. Check the doc at > > http://mojo.codehaus.org/build-helper-maven-plugin > > > > Regards > > Jeff MAURY > > > > On Sat, Nov 26, 2011 at 1:58 AM, Stephen Connolly < > > stephen.alan.conno...@gmail.com> wrote: > > > >> either mandate a parent pom... they will have to reference your plugin > in > >> their pom and the execution from the pluginmgmt will be pulled in, or > >> custom lifecycle (they will need to ref the plugin and set extensions to > >> true... > >> > >> themselves the only two ways to skin the cat > >> > >> - Stephen > >> > >> --- > >> Sent from my Android phone, so random spelling mistakes, random nonsense > >> words and other nonsense are a direct result of using swype to type on > the > >> screen > >> On 25 Nov 2011 22:17, "Andrew Eisenberg" > >> wrote: > >> > >> > Hi all, > >> > > >> > I am trying to create a maven plugin that transparently adds a new > >> > source folder to the project. It is always the same folder and so > >> > there should be no configuration required from the user. I've been > >> > going through > >> > > http://www.sonatype.com/books/mvnref-book/reference/writing-plugins.html > >> > , but I can't find anything that solves my problem. > >> > > >> > I created a plugin project with the following mojo: > >> > > >> > > >> > /** > >> > * @goal add-xxx-source > >> > * @phase compile > >> > * @execute phase="compile" > >> > */ > >> > public class AddGroovySourceFolders extends AbstractMojo { > >> >/** > >> > * @parameter expression="${project}" > >> > * @required > >> > * @readonly > >> > */ > >> >private MavenProject project; > >> > > >> >public void execute() throws MojoExecutionException, > >> > MojoFailureException { > >> >getLog().info("Adding /src/main/xxx to the list of source > >> folders"); > >> >this.project.addCompileSourceRoot(project.getBasedir() + > >> > "/src/main/xxx"); > >> >} > >> > } > >> > > >> > Now, the only way that I can get this mojo executing is by explicitly > >> > adding it in the executions section of the plugin dependency: > >> > > >> > > >> >org.codehaus.groovy > >> >xxx-compiler > >> >2.6.0-01-SNAPSHOT > >> > > >> > > >> >add-source > >> > > >> > generate-sources > >> > > >> > > >> > add-xxx-source > >> > > >> > > >> > > >> > > >> > > >> > I would like it so that consumers of my plugin can leave out the > >> > extensions section and have the mojo executed automatically, like > >> > this: > >> > > >> > > >> >org.codehaus.groovy > >> >xxx-compiler > >> >2.6.0-01-SNAPSHOT > >> > > >> > > >> > Is this possible? And how can I do this? > >> > > >> > thanks for your help. > >> > > >> > - > >> > To unsubscribe, e-mail: users-unsubscr...@maven.apache.org > >> > For additional commands, e-mail: users-h...@maven.apache.org > >> > > >> > > >> > > > > > > > > -- > > "Legacy code" often differs from its suggested alternative by actually > > working and scaling. > > - Bjarne Stroustrup > > > > http://www.jeffmaury.com > > http://riadiscuss.jeffmaury.com > > http://www.twitter.com/jeffmaury > > - > To unsubscribe, e-mail: users-unsubscr...@maven.apache.org > For additional commands, e-mail: users-h...@maven.apache
Re: writing a maven plugin that transparently adds a new source folder
Thanks, Jeff and Stephen for your answers. I know about the build-helper-maven-plugin, but this adds about 20 lines of configuration to the pom and I was hoping to avoid that. Also, forcing users to specify a parent pom is not feasible since users will likely have their own parent poms to use. My goal is to simplify the configuration of the pom so that with just about 3-4 lines of configuration, all the functionality happens automatically. Are you suggesting that this is not possible? ps- Apologies for not responding sooner, but somehow these messages have been ending up in my spam folder. On Sat, Nov 26, 2011 at 9:59 AM, Jeff MAURY wrote: > If you need to add source folders, there is an existing Maven plugin to do > it: the build-helper-maven-plugin. Check the doc at > http://mojo.codehaus.org/build-helper-maven-plugin > > Regards > Jeff MAURY > > On Sat, Nov 26, 2011 at 1:58 AM, Stephen Connolly < > stephen.alan.conno...@gmail.com> wrote: > >> either mandate a parent pom... they will have to reference your plugin in >> their pom and the execution from the pluginmgmt will be pulled in, or >> custom lifecycle (they will need to ref the plugin and set extensions to >> true... >> >> themselves the only two ways to skin the cat >> >> - Stephen >> >> --- >> Sent from my Android phone, so random spelling mistakes, random nonsense >> words and other nonsense are a direct result of using swype to type on the >> screen >> On 25 Nov 2011 22:17, "Andrew Eisenberg" >> wrote: >> >> > Hi all, >> > >> > I am trying to create a maven plugin that transparently adds a new >> > source folder to the project. It is always the same folder and so >> > there should be no configuration required from the user. I've been >> > going through >> > http://www.sonatype.com/books/mvnref-book/reference/writing-plugins.html >> > , but I can't find anything that solves my problem. >> > >> > I created a plugin project with the following mojo: >> > >> > >> > /** >> > * @goal add-xxx-source >> > * @phase compile >> > * @execute phase="compile" >> > */ >> > public class AddGroovySourceFolders extends AbstractMojo { >> > /** >> > * @parameter expression="${project}" >> > * @required >> > * @readonly >> > */ >> > private MavenProject project; >> > >> > public void execute() throws MojoExecutionException, >> > MojoFailureException { >> > getLog().info("Adding /src/main/xxx to the list of source >> folders"); >> > this.project.addCompileSourceRoot(project.getBasedir() + >> > "/src/main/xxx"); >> > } >> > } >> > >> > Now, the only way that I can get this mojo executing is by explicitly >> > adding it in the executions section of the plugin dependency: >> > >> > >> > org.codehaus.groovy >> > xxx-compiler >> > 2.6.0-01-SNAPSHOT >> > >> > >> > add-source >> > >> > generate-sources >> > >> > >> > add-xxx-source >> > >> > >> > >> > >> > >> > I would like it so that consumers of my plugin can leave out the >> > extensions section and have the mojo executed automatically, like >> > this: >> > >> > >> > org.codehaus.groovy >> > xxx-compiler >> > 2.6.0-01-SNAPSHOT >> > >> > >> > Is this possible? And how can I do this? >> > >> > thanks for your help. >> > >> > - >> > To unsubscribe, e-mail: users-unsubscr...@maven.apache.org >> > For additional commands, e-mail: users-h...@maven.apache.org >> > >> > >> > > > > -- > "Legacy code" often differs from its suggested alternative by actually > working and scaling. > - Bjarne Stroustrup > > http://www.jeffmaury.com > http://riadiscuss.jeffmaury.com > http://www.twitter.com/jeffmaury - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org
Re: writing a maven plugin that transparently adds a new source folder
If you need to add source folders, there is an existing Maven plugin to do it: the build-helper-maven-plugin. Check the doc at http://mojo.codehaus.org/build-helper-maven-plugin Regards Jeff MAURY On Sat, Nov 26, 2011 at 1:58 AM, Stephen Connolly < stephen.alan.conno...@gmail.com> wrote: > either mandate a parent pom... they will have to reference your plugin in > their pom and the execution from the pluginmgmt will be pulled in, or > custom lifecycle (they will need to ref the plugin and set extensions to > true... > > themselves the only two ways to skin the cat > > - Stephen > > --- > Sent from my Android phone, so random spelling mistakes, random nonsense > words and other nonsense are a direct result of using swype to type on the > screen > On 25 Nov 2011 22:17, "Andrew Eisenberg" > wrote: > > > Hi all, > > > > I am trying to create a maven plugin that transparently adds a new > > source folder to the project. It is always the same folder and so > > there should be no configuration required from the user. I've been > > going through > > http://www.sonatype.com/books/mvnref-book/reference/writing-plugins.html > > , but I can't find anything that solves my problem. > > > > I created a plugin project with the following mojo: > > > > > > /** > > * @goal add-xxx-source > > * @phase compile > > * @execute phase="compile" > > */ > > public class AddGroovySourceFolders extends AbstractMojo { > >/** > > * @parameter expression="${project}" > > * @required > > * @readonly > > */ > >private MavenProject project; > > > >public void execute() throws MojoExecutionException, > > MojoFailureException { > >getLog().info("Adding /src/main/xxx to the list of source > folders"); > >this.project.addCompileSourceRoot(project.getBasedir() + > > "/src/main/xxx"); > >} > > } > > > > Now, the only way that I can get this mojo executing is by explicitly > > adding it in the executions section of the plugin dependency: > > > > > >org.codehaus.groovy > >xxx-compiler > >2.6.0-01-SNAPSHOT > > > > > >add-source > > > > generate-sources > > > > > > add-xxx-source > > > > > > > > > > > > I would like it so that consumers of my plugin can leave out the > > extensions section and have the mojo executed automatically, like > > this: > > > > > >org.codehaus.groovy > >xxx-compiler > >2.6.0-01-SNAPSHOT > > > > > > Is this possible? And how can I do this? > > > > thanks for your help. > > > > - > > To unsubscribe, e-mail: users-unsubscr...@maven.apache.org > > For additional commands, e-mail: users-h...@maven.apache.org > > > > > -- "Legacy code" often differs from its suggested alternative by actually working and scaling. - Bjarne Stroustrup http://www.jeffmaury.com http://riadiscuss.jeffmaury.com http://www.twitter.com/jeffmaury
Re: writing a maven plugin that transparently adds a new source folder
either mandate a parent pom... they will have to reference your plugin in their pom and the execution from the pluginmgmt will be pulled in, or custom lifecycle (they will need to ref the plugin and set extensions to true... themselves the only two ways to skin the cat - Stephen --- Sent from my Android phone, so random spelling mistakes, random nonsense words and other nonsense are a direct result of using swype to type on the screen On 25 Nov 2011 22:17, "Andrew Eisenberg" wrote: > Hi all, > > I am trying to create a maven plugin that transparently adds a new > source folder to the project. It is always the same folder and so > there should be no configuration required from the user. I've been > going through > http://www.sonatype.com/books/mvnref-book/reference/writing-plugins.html > , but I can't find anything that solves my problem. > > I created a plugin project with the following mojo: > > > /** > * @goal add-xxx-source > * @phase compile > * @execute phase="compile" > */ > public class AddGroovySourceFolders extends AbstractMojo { >/** > * @parameter expression="${project}" > * @required > * @readonly > */ >private MavenProject project; > >public void execute() throws MojoExecutionException, > MojoFailureException { >getLog().info("Adding /src/main/xxx to the list of source folders"); >this.project.addCompileSourceRoot(project.getBasedir() + > "/src/main/xxx"); >} > } > > Now, the only way that I can get this mojo executing is by explicitly > adding it in the executions section of the plugin dependency: > > >org.codehaus.groovy >xxx-compiler >2.6.0-01-SNAPSHOT > > >add-source > > generate-sources > > > add-xxx-source > > > > > > I would like it so that consumers of my plugin can leave out the > extensions section and have the mojo executed automatically, like > this: > > >org.codehaus.groovy >xxx-compiler >2.6.0-01-SNAPSHOT > > > Is this possible? And how can I do this? > > thanks for your help. > > - > To unsubscribe, e-mail: users-unsubscr...@maven.apache.org > For additional commands, e-mail: users-h...@maven.apache.org > >
writing a maven plugin that transparently adds a new source folder
Hi all, I am trying to create a maven plugin that transparently adds a new source folder to the project. It is always the same folder and so there should be no configuration required from the user. I've been going through http://www.sonatype.com/books/mvnref-book/reference/writing-plugins.html , but I can't find anything that solves my problem. I created a plugin project with the following mojo: /** * @goal add-xxx-source * @phase compile * @execute phase="compile" */ public class AddGroovySourceFolders extends AbstractMojo { /** * @parameter expression="${project}" * @required * @readonly */ private MavenProject project; public void execute() throws MojoExecutionException, MojoFailureException { getLog().info("Adding /src/main/xxx to the list of source folders"); this.project.addCompileSourceRoot(project.getBasedir() + "/src/main/xxx"); } } Now, the only way that I can get this mojo executing is by explicitly adding it in the executions section of the plugin dependency: org.codehaus.groovy xxx-compiler 2.6.0-01-SNAPSHOT add-source generate-sources add-xxx-source I would like it so that consumers of my plugin can leave out the extensions section and have the mojo executed automatically, like this: org.codehaus.groovy xxx-compiler 2.6.0-01-SNAPSHOT Is this possible? And how can I do this? thanks for your help. - To unsubscribe, e-mail: users-unsubscr...@maven.apache.org For additional commands, e-mail: users-h...@maven.apache.org