Have you look at <DependencyManagement> node?
Look at 
http://jira.codehaus.org/browse/MNG-743 and download the
sample-m2-project.jar from the attachement.

I.E.
   <dependencyManagement>
      <dependencies>
         <dependency>
             <groupId>net.bzdyl.demo</groupId>
            <artifactId>demo-par</artifactId>
            <version>1.0</version>
         </dependency>
   </dependencyManagement>

Note: by default maven-jar-plugins hardcoded the .jar file name
extension. I don't think it's hard to patch the
maven-components/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar/JarMojo.java
file to suport this feature.

Regards,
Edward Yakop

Note: 
The attached file is a sample implementation of JarMojo.

To use:
0. Check out maven-source tree
    svn co https://svn.apache.org/repos/asf/maven/components/trunk
maven-components
    or follow
    http://maven.apache.org/maven2/developers/building.html

1. Update JarMojo.java

    Replace the JarMojo.java inside 
   
maven-components/maven-plugins/maven-jar-plugin/src/main/java/org/apache/maven/plugin/jar
   and
   cd maven-components/maven-plugins/maven-jar-plugin ; m2 install

2. Replace pom.xml of demo-par dir.

<project xmlns="http://maven.apache.org/POM/4.0.0";
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd";>
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>net.bzdyl.demo</groupId>
    <artifactId>demo</artifactId>
    <version>1.0-SNAPSHOT</version>
  </parent>
  <groupId>net.bzdyl.demo</groupId>
  <artifactId>demo-par</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
          <finalNameExt>par</finalNameExt> <!-- Notice the ext is par -->
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
      <groupId>javax.persistence</groupId>
      <artifactId>ejb</artifactId>
      <version>3.0-public_review</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>
</project>

On 9/5/05, Piotr Bzdyl <[EMAIL PROTECTED]> wrote:
> 
> >>Additional info: Maven 2 revision I used is: 278636.
> >>
> >>And one additional question:
> >>
> >>Can I specify version in the parent pom and use inherited value in
> >>subprojects or I have to specify version separately in every pom.xml?
> >>
> >>
> >
> >You do not have to specify the version in the pom, it will use the one
> >stated in the <parent> element.
> >
> >
> What about dependencies in the dependent projects, for example:
> I specify in the parent pom.xml version 2.1. Then what I should write in
> the demo-ejb pom.xml in the version attribute:
> <dependency>
>       <groupId>net.bzdyl.demo</groupId>
>       <artifactId>demo-par</artifactId>
>       <version>????????</version>
>       <type>par</type>
>       <scope>compile</scope>
>     </dependency>
> 
> I would like to use the same version as the demo-ejb version (without
> specifing it literally).
> 
> Best regards,
> Piotrek
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
>
package org.apache.maven.plugin.jar;

/*
 * Copyright 2001-2005 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import org.apache.maven.archiver.MavenArchiveConfiguration;
import org.apache.maven.archiver.MavenArchiver;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;

import java.io.File;

/**
 * @author <a href="[EMAIL PROTECTED]">Emmanuel Venisse</a>
 * @version $Id: JarMojo.java 225731 2005-07-28 09:32:32Z brett $
 * @goal jar
 * @phase package
 * @description build a jar
 */
public class JarMojo
    extends AbstractMojo
{
    
    private static final String[] DEFAULT_EXCLUDES = new 
String[]{"**/package.html"};

    private static final String[] DEFAULT_INCLUDES = new String[]{"**/**"};

    /**
     * @todo Change type to File
     * 
     * @parameter expression="${project.build.directory}"
     * @required
     * @readonly
     */
    private String basedir;

    /**
     * @parameter alias="jarName" expression="${project.build.finalName}"
     * @required
     */
    private String finalName;

    /**
     * @parameter alias="jarNameExt" expression="${project.build.finalNameExt}"
     * default-value="jar"
     * @required
     */
    private String finalNameExt = "jar";

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

    /**
     * @parameter expression="${project}"
     * @required
     * @readonly
     */
    private MavenProject project;

    /**
     * @parameter
     */
    private MavenArchiveConfiguration archive = new MavenArchiveConfiguration();

    /**
     * @todo Add license files in META-INF directory.
     */
    public void execute()
        throws MojoExecutionException
    {
        File jarFile = new File( basedir, finalName + "." + finalNameExt );

        MavenArchiver archiver = new MavenArchiver();

        archiver.setOutputFile( jarFile );

        try
        {
            File contentDirectory = new File( outputDirectory );
            if ( !contentDirectory.exists() )
            {
                getLog().warn( "JAR will be empty - no content was marked for 
inclusion!" );
            }
            else
            {
                archiver.getArchiver().addDirectory( contentDirectory, 
DEFAULT_INCLUDES, DEFAULT_EXCLUDES );
            }

            archiver.createArchive( project, archive );

            project.getArtifact().setFile( jarFile );
        }
        catch ( Exception e )
        {
            // TODO: improve error handling
            throw new MojoExecutionException( "Error assembling JAR", e );
        }
    }

}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to