You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by "G.B." <gb...@laposte.net> on 2006/04/12 17:11:47 UTC

Is execution inheritance working ?

Hi,
I want to do something very simple : copy my pom file to a
known location (in the classpath), and I want that to be done
in all my project/subprojects.

I have main project A with sub component B and C
A contains the super pom B and C pom are inherited from A.
First thing I did is create the following
<build>
<plugins>
…
<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-antrun-plugin</artifactId>
		<executions>
			<execution>
				<id>pomAntCopy</id>
				<goals>
					<goal>run</goal>
				</goals>
				<phase>process-resources</phase>
				<configuration>
					<tasks>
						<copy file="${basedir}/pom.xml"
todir="${project.build.outputDirectory}/myLocation/${groupId}/${artifactId}"
overwrite="true"/>
					</tasks>
				</configuration>		
			</execution>
		</executions>
	</plugin>

If I  do mvn process-resources I only get that result in
A/target/… B and C are just ignoring it
After a lot of tries I did 

<plugin>
	<inherited>true</inherited>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-antrun-plugin</artifactId>
		<executions>
			<inherited>true</inherited>
			<execution>
				<inherited>true</inherited>
				<id>pomAntCopy</id>
				<goals>
					<inherited>true</inherited>
					<goal>run</goal>
				</goals>
				<phase>process-resources</phase>
				<configuration>
					<inherited>true</inherited>
					<tasks>
						<copy file="${basedir}/pom.xml"
todir="${project.build.outputDirectory}/META-INF/maven/${groupId}/${artifactId}-ant"
overwrite="true"/>			</tasks>
				</configuration>
			</execution>
		</executions>
	</plugin>

I know I added too much inherited but I wanted to make sur
maven would understand I want inheritance :o) … it did not work

I tried to do a stupid plugin:

/**
 * @goal copy
 * @description Copy Pom into location in classpath to be use
by life cycle tool durring
 *              developpment process
 * @execute phase="process-resources"
 */
public class DevelopmentPomReplicator extends AbstractMojo {

  /**
   * The project to process.
   * 
   * @parameter expression="${project}"
   * @required
   * @readonly
   */
  private MavenProject mavenProject;

  /**
   * The project base dir.
   * 
   * @parameter expression="${basedir}"
   * @required
   * @readonly
   */
  private String pomDir;

  /**
   * @parameter expression="${project.build.directory}"
   * @required
   */
  private String outDir;

public void execute() throws MojoExecutionException,
MojoFailureException {
    final int BUFFER = 2048;
    if("jar".equalsIgnoreCase(mavenProject.getPackaging())){
      try{
        String outputSubPath ="/mylocation/" +
mavenProject.getGroupId() + "/" + mavenProject.getArtifactId();
        File pomIn = new File(pomDir + "/pom.xml");
        BufferedInputStream l_bis = new BufferedInputStream(
new FileInputStream(pomIn));
        File pomOut = new File(outDir + outputSubPath +
"/pom.xml");
        pomOut.getParentFile().mkdirs();
        BufferedOutputStream l_bos = new BufferedOutputStream(
new FileOutputStream(pomOut));
        byte data[] = new byte[BUFFER];
        int count;
        while ((count = l_bis.read(data, 0, BUFFER)) != -1) {
          l_bos.write(data, 0, count);
        }
        l_bos.flush();
        l_bos.close();
      } catch(Exception e){
        throw new MojoExecutionException("copy", e);
      }
      
    }

  }}

in A pom I added
<plugin>
<inherited>true</inherited>
	<groupId>test.build.inheritance</groupId>
	<artifactId>DevelopmentPomReplicator</artifactId>
	<configuration>
		<outDir>${project.build.directory}/toto</outDir>
	</configuration>
		<executions>
			<inherited>true</inherited>
				<execution>
					<inherited>true</inherited>
					<id>pomReplicatorCopy</id>
					<phase>process-resources</phase>
					<goals>
						<goal>copy</goal>
					</goals>
				</execution>
			</executions>
		</plugin>

did not work … only A execute it … more over I have the
following message :

[INFO] Preparing DevelopmentPomReplicator:copy

[WARNING] Removing: copy from forked lifecycle, to prevent
recursive invocation.

Arg no please no … it’s exactly what I want! Recursive invocation.
How can I enable it ?
How should I proceed ?

Please help.
Thanks in advance
Guillaume

Accédez au courrier électronique de La Poste : www.laposte.net ; 
3615 LAPOSTENET (0,34 €/mn) ; tél : 08 92 68 13 50 (0,34€/mn)




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


Re: Is execution inheritance working ?

Posted by "G. B." <gb...@laposte.net>.
I'm lost.
if I add this to the pom it does not work, however, if in A folder I call
mvn test.build.inheritance:DevelopmentPomReplicator:copy Pom is actulay
copied correctly in B and C

how should I proceed to have it automatically (automagically) been performed 
on process-resources? should I extends current life cycle ?

G. B. wrote:
> 
> in A pom I added
> <plugin>
> <inherited>true</inherited>
> 	<groupId>test.build.inheritance</groupId>
> 	<artifactId>DevelopmentPomReplicator</artifactId>
> 	<configuration>
> 		<outDir>${project.build.directory}/toto</outDir>
> 	</configuration>
> 		<executions>
> 			<inherited>true</inherited>
> 				<execution>
> 					<inherited>true</inherited>
> 					<id>pomReplicatorCopy</id>
> 					<phase>process-resources</phase>
> 					<goals>
> 						<goal>copy</goal>
> 					</goals>
> 				</execution>
> 			</executions>
> 		</plugin>
> 
> did not work … only A execute it … more over I have the
> following message :
> 
> [INFO] Preparing DevelopmentPomReplicator:copy
> 
> [WARNING] Removing: copy from forked lifecycle, to prevent
> recursive invocation.
> 
--
View this message in context: http://www.nabble.com/Is-execution-inheritance-working--t1438786.html#a3900156
Sent from the Maven - Users forum at Nabble.com.


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


Re: Is execution inheritance working ?

Posted by Tim Kettler <ti...@udo.edu>.
I don't use eclipse so I can't say much about this. But when i run 'mvn eclipse:eclipse' 
it gives this warning:

[INFO] ----------------------------------------------------------------------------
[INFO] Building suba
[INFO]    task-segment: [eclipse:eclipse]
[INFO] ----------------------------------------------------------------------------
[INFO] Preparing eclipse:eclipse
[INFO] No goals needed for project - skipping
[INFO] [eclipse:eclipse]
[WARNING] This plugin currently doesn't support include patterns for resources. Adding the 
entire directory.

Can this be the cause of the problem? Perhaps someone with more experience with the 
eclipse plugin can comment.

-Tim

G. B. schrieb:
> mmm I don't know what I did ... sorry.
> This is working but it create an other bigger issues:
> try doing mvn eclipse:eclipse on it
> 
> you would end up with a .classpath like this:
> 
> <classpath>
>   <classpathentry kind="src" path="." output="myLocation/test/suba"/>
>   <classpathentry kind="src" path="src/main/java"/>
>   <classpathentry kind="output" path="target/classes"/>
>   <classpathentry kind="con"
> path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
> </classpath>
> 
> the two src path are overriding each other ...
> eclipse says :
> Error		suba	Cannot nest 'suba/src/main/java' inside 'suba'. To enable the
> nesting exclude 'src/' from 'suba'	Build path
> 
> I tryied with adding <excludes><exclude>**/*</exclude></excludes> in main
> pom but that did not change anything.
> any idea ?
> 
> --
> View this message in context: http://www.nabble.com/Is-execution-inheritance-working--t1438786.html#a3913667
> Sent from the Maven - Users forum at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> 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: Is execution inheritance working ?

Posted by "G. B." <gb...@laposte.net>.
mmm I don't know what I did ... sorry.
This is working but it create an other bigger issues:
try doing mvn eclipse:eclipse on it

you would end up with a .classpath like this:

<classpath>
  <classpathentry kind="src" path="." output="myLocation/test/suba"/>
  <classpathentry kind="src" path="src/main/java"/>
  <classpathentry kind="output" path="target/classes"/>
  <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
</classpath>

the two src path are overriding each other ...
eclipse says :
Error		suba	Cannot nest 'suba/src/main/java' inside 'suba'. To enable the
nesting exclude 'src/' from 'suba'	Build path

I tryied with adding <excludes><exclude>**/*</exclude></excludes> in main
pom but that did not change anything.
any idea ?

--
View this message in context: http://www.nabble.com/Is-execution-inheritance-working--t1438786.html#a3913667
Sent from the Maven - Users forum at Nabble.com.


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


Re: Is execution inheritance working ?

Posted by Tim Kettler <ti...@udo.edu>.
I created the following simple test project:

test
   |--suba
   |    |
   |    pom.xml
   |--subb
   |    |
   |    pom.xml
   |
   pom.xml

-- test: pom.xml -------------------
<project>
   <modelVersion>4.0.0</modelVersion>

   <groupId>test</groupId>
   <artifactId>test</artifactId>
   <version>1.0-SNAPSHOT</version>
	
   <packaging>pom</packaging>

   <name>testparent</name>
	
   <modules>
     <module>suba</module>
     <module>subb</module>
   </modules>

   <build>
     <resources>
       <resource>
         <targetPath>myLocation/${groupId}/${artifactId}</targetPath>
         <directory>${basedir}</directory>
         <includes>
           <include>pom.xml</include>
         </includes>
       </resource>
     </resources>
   </build>
</project>
------------------------------------

-- suba: pom.xml -------------------
<project>
   <modelVersion>4.0.0</modelVersion>

   <parent>	
     <groupId>test</groupId>
     <artifactId>test</artifactId>
     <version>1.0-SNAPSHOT</version>
   </parent>		

   <groupId>test</groupId>
   <artifactId>suba</artifactId>
   <version>1.0-SNAPSHOT</version>
	
   <packaging>jar</packaging>
	
   <name>suba</name>
</project>
------------------------------------

-- subb: pom.xml -------------------
<project>
   <modelVersion>4.0.0</modelVersion>

   <parent>	
     <groupId>test</groupId>
     <artifactId>test</artifactId>
     <version>1.0-SNAPSHOT</version>
   </parent>		

   <groupId>test</groupId>
   <artifactId>subb</artifactId>
   <version>1.0-SNAPSHOT</version>
	
   <packaging>jar</packaging>
	
   <name>suba</name>
</project>
------------------------------------

When I do:

$cd test
$mvn resources:resources

the defined resource for the pom gets copied to the respective subprojects 
target/classes/myLocation/${groupId}/${artifactId}.

Is this the behaviour you want? In the test project this works without any problem.

-Tim


G. B. schrieb:
> Oups ...
> here is what I did :
> in my main pom I added:
> <resources>
> 	<resource>
> 		<targetPath>myLocation/${groupId}/${artifactId}</targetPath>
> 		<directory>${basedir}</directory>
> 		<includes>
> 			<include>pom.xml</include>
> 		</includes>
> 	</resource>
> </resources>
> When I run that on component A that contains sub component B and C nothing
> appends ...
> when I run it on B or C I get it done ... I want that to be inherited and
> when executed from A I wand B and C copying the pom :o(
> 
> any idea ?
> Guillaume
> 
> 
> John Casey-3 wrote:
>> why not add a <resource/> with the directory pointed at ${basedir}, and a
>> single include of pom.xml with excludes of **/*?
>>
>> Then, your pom would be copied into target/classes on prepare-resources,
>> IIRC.
>>
>> -john
>>
>>
> --
> View this message in context: http://www.nabble.com/Is-execution-inheritance-working--t1438786.html#a3895618
> Sent from the Maven - Users forum at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> 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: Is execution inheritance working ?

Posted by "G. B." <gb...@laposte.net>.
Oups ...
here is what I did :
in my main pom I added:
<resources>
	<resource>
		<targetPath>myLocation/${groupId}/${artifactId}</targetPath>
		<directory>${basedir}</directory>
		<includes>
			<include>pom.xml</include>
		</includes>
	</resource>
</resources>
When I run that on component A that contains sub component B and C nothing
appends ...
when I run it on B or C I get it done ... I want that to be inherited and
when executed from A I wand B and C copying the pom :o(

any idea ?
Guillaume


John Casey-3 wrote:
> 
> why not add a <resource/> with the directory pointed at ${basedir}, and a
> single include of pom.xml with excludes of **/*?
> 
> Then, your pom would be copied into target/classes on prepare-resources,
> IIRC.
> 
> -john
> 
> 
--
View this message in context: http://www.nabble.com/Is-execution-inheritance-working--t1438786.html#a3895618
Sent from the Maven - Users forum at Nabble.com.


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


Re: Is execution inheritance working ?

Posted by Tim Kettler <ti...@udo.edu>.
Hi,

Maven includes the pom.xml by default under META-INF/maven/${grouId}/${artifactId}/pom.xml 
in the generated artifact. So if you just need the file during runtime it is already there :-)

-Tim

G.B. schrieb:
> Hi,
> I want to do something very simple : copy my pom file to a
> known location (in the classpath), and I want that to be done
> in all my project/subprojects.
> 
> I have main project A with sub component B and C
> A contains the super pom B and C pom are inherited from A.
> First thing I did is create the following
> <build>
> <plugins>
> …
> <plugin>
> 	<groupId>org.apache.maven.plugins</groupId>
> 	<artifactId>maven-antrun-plugin</artifactId>
> 		<executions>
> 			<execution>
> 				<id>pomAntCopy</id>
> 				<goals>
> 					<goal>run</goal>
> 				</goals>
> 				<phase>process-resources</phase>
> 				<configuration>
> 					<tasks>
> 						<copy file="${basedir}/pom.xml"
> todir="${project.build.outputDirectory}/myLocation/${groupId}/${artifactId}"
> overwrite="true"/>
> 					</tasks>
> 				</configuration>		
> 			</execution>
> 		</executions>
> 	</plugin>
> 
> If I  do mvn process-resources I only get that result in
> A/target/… B and C are just ignoring it
> After a lot of tries I did 
> 
> <plugin>
> 	<inherited>true</inherited>
> 	<groupId>org.apache.maven.plugins</groupId>
> 	<artifactId>maven-antrun-plugin</artifactId>
> 		<executions>
> 			<inherited>true</inherited>
> 			<execution>
> 				<inherited>true</inherited>
> 				<id>pomAntCopy</id>
> 				<goals>
> 					<inherited>true</inherited>
> 					<goal>run</goal>
> 				</goals>
> 				<phase>process-resources</phase>
> 				<configuration>
> 					<inherited>true</inherited>
> 					<tasks>
> 						<copy file="${basedir}/pom.xml"
> todir="${project.build.outputDirectory}/META-INF/maven/${groupId}/${artifactId}-ant"
> overwrite="true"/>			</tasks>
> 				</configuration>
> 			</execution>
> 		</executions>
> 	</plugin>
> 
> I know I added too much inherited but I wanted to make sur
> maven would understand I want inheritance :o) … it did not work
> 
> I tried to do a stupid plugin:
> 
> /**
>  * @goal copy
>  * @description Copy Pom into location in classpath to be use
> by life cycle tool durring
>  *              developpment process
>  * @execute phase="process-resources"
>  */
> public class DevelopmentPomReplicator extends AbstractMojo {
> 
>   /**
>    * The project to process.
>    * 
>    * @parameter expression="${project}"
>    * @required
>    * @readonly
>    */
>   private MavenProject mavenProject;
> 
>   /**
>    * The project base dir.
>    * 
>    * @parameter expression="${basedir}"
>    * @required
>    * @readonly
>    */
>   private String pomDir;
> 
>   /**
>    * @parameter expression="${project.build.directory}"
>    * @required
>    */
>   private String outDir;
> 
> public void execute() throws MojoExecutionException,
> MojoFailureException {
>     final int BUFFER = 2048;
>     if("jar".equalsIgnoreCase(mavenProject.getPackaging())){
>       try{
>         String outputSubPath ="/mylocation/" +
> mavenProject.getGroupId() + "/" + mavenProject.getArtifactId();
>         File pomIn = new File(pomDir + "/pom.xml");
>         BufferedInputStream l_bis = new BufferedInputStream(
> new FileInputStream(pomIn));
>         File pomOut = new File(outDir + outputSubPath +
> "/pom.xml");
>         pomOut.getParentFile().mkdirs();
>         BufferedOutputStream l_bos = new BufferedOutputStream(
> new FileOutputStream(pomOut));
>         byte data[] = new byte[BUFFER];
>         int count;
>         while ((count = l_bis.read(data, 0, BUFFER)) != -1) {
>           l_bos.write(data, 0, count);
>         }
>         l_bos.flush();
>         l_bos.close();
>       } catch(Exception e){
>         throw new MojoExecutionException("copy", e);
>       }
>       
>     }
> 
>   }}
> 
> in A pom I added
> <plugin>
> <inherited>true</inherited>
> 	<groupId>test.build.inheritance</groupId>
> 	<artifactId>DevelopmentPomReplicator</artifactId>
> 	<configuration>
> 		<outDir>${project.build.directory}/toto</outDir>
> 	</configuration>
> 		<executions>
> 			<inherited>true</inherited>
> 				<execution>
> 					<inherited>true</inherited>
> 					<id>pomReplicatorCopy</id>
> 					<phase>process-resources</phase>
> 					<goals>
> 						<goal>copy</goal>
> 					</goals>
> 				</execution>
> 			</executions>
> 		</plugin>
> 
> did not work … only A execute it … more over I have the
> following message :
> 
> [INFO] Preparing DevelopmentPomReplicator:copy
> 
> [WARNING] Removing: copy from forked lifecycle, to prevent
> recursive invocation.
> 
> Arg no please no … it’s exactly what I want! Recursive invocation.
> How can I enable it ?
> How should I proceed ?
> 
> Please help.
> Thanks in advance
> Guillaume
> 
> Accédez au courrier électronique de La Poste : www.laposte.net ; 
> 3615 LAPOSTENET (0,34 €/mn) ; tél : 08 92 68 13 50 (0,34€/mn)
> 
> 
> 
> 
> ---------------------------------------------------------------------
> 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