mirror of https://github.com/apache/maven.git
PR: MNG-816
allow attachment of another jar during the build process git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@293542 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d8875a4f7d
commit
9f8c7e326a
|
@ -36,7 +36,6 @@
|
|||
<profile>
|
||||
<id>all-models</id>
|
||||
<build>
|
||||
<finalName>${pom.artifactId}-${pom.version}-all</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.modello</groupId>
|
||||
|
@ -57,6 +56,20 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<configuration>
|
||||
<classifier>all</classifier>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
|
|
|
@ -21,13 +21,14 @@ 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 org.apache.maven.project.MavenProjectHelper;
|
||||
import org.codehaus.plexus.archiver.jar.JarArchiver;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Base class for creating a jar from project classes.
|
||||
*
|
||||
*
|
||||
* @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
|
@ -45,7 +46,6 @@ public abstract class AbstractJarMojo
|
|||
* @parameter expression="${project.build.directory}"
|
||||
* @required
|
||||
* @readonly
|
||||
*
|
||||
* @todo Change type to File
|
||||
*/
|
||||
private String basedir;
|
||||
|
@ -81,24 +81,26 @@ public abstract class AbstractJarMojo
|
|||
* @parameter
|
||||
*/
|
||||
private MavenArchiveConfiguration archive = new MavenArchiveConfiguration();
|
||||
|
||||
|
||||
/**
|
||||
* @component
|
||||
*/
|
||||
private MavenProjectHelper projectHelper;
|
||||
|
||||
/**
|
||||
* Return the specific output directory to serve as the root for the archive.
|
||||
*/
|
||||
protected abstract File getOutputDirectory();
|
||||
|
||||
|
||||
protected final MavenProject getProject()
|
||||
{
|
||||
return project;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Overload this to produce a test-jar, for example.
|
||||
*/
|
||||
protected String getClassifier()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
protected abstract String getClassifier();
|
||||
|
||||
/**
|
||||
* Generates the JAR.
|
||||
|
@ -109,7 +111,7 @@ public abstract class AbstractJarMojo
|
|||
throws MojoExecutionException
|
||||
{
|
||||
String classifier = getClassifier();
|
||||
|
||||
|
||||
if ( classifier == null )
|
||||
{
|
||||
classifier = "";
|
||||
|
@ -118,7 +120,7 @@ public abstract class AbstractJarMojo
|
|||
{
|
||||
classifier = "-" + classifier;
|
||||
}
|
||||
|
||||
|
||||
File jarFile = new File( basedir, finalName + classifier + ".jar" );
|
||||
|
||||
MavenArchiver archiver = new MavenArchiver();
|
||||
|
@ -140,7 +142,7 @@ public abstract class AbstractJarMojo
|
|||
}
|
||||
|
||||
archiver.createArchive( project, archive );
|
||||
|
||||
|
||||
return jarFile;
|
||||
}
|
||||
catch ( Exception e )
|
||||
|
@ -149,4 +151,25 @@ public abstract class AbstractJarMojo
|
|||
throw new MojoExecutionException( "Error assembling JAR", e );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the JAR.
|
||||
*
|
||||
* @todo Add license files in META-INF directory.
|
||||
*/
|
||||
public void execute()
|
||||
throws MojoExecutionException
|
||||
{
|
||||
File jarFile = createArchive();
|
||||
|
||||
String classifier = getClassifier();
|
||||
if ( classifier != null )
|
||||
{
|
||||
projectHelper.attachArtifact( getProject(), "jar", classifier, jarFile );
|
||||
}
|
||||
else
|
||||
{
|
||||
getProject().getArtifact().setFile( jarFile );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,16 +42,15 @@ public class JarMojo
|
|||
private File outputDirectory;
|
||||
|
||||
/**
|
||||
* Generates the JAR.
|
||||
* Classifier to add to the artifact generated. If given, the artifact will be an attachment instead.
|
||||
*
|
||||
* @todo Add license files in META-INF directory.
|
||||
* @parameter
|
||||
*/
|
||||
public void execute()
|
||||
throws MojoExecutionException
|
||||
private String classifier;
|
||||
|
||||
protected String getClassifier()
|
||||
{
|
||||
File jarFile = createArchive();
|
||||
|
||||
getProject().getArtifact().setFile( jarFile );
|
||||
return classifier;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -42,31 +42,11 @@ public class TestJarMojo
|
|||
*/
|
||||
private File testOutputDirectory;
|
||||
|
||||
/**
|
||||
* @component role="org.apache.maven.project.MavenProjectHelper"
|
||||
*/
|
||||
private MavenProjectHelper projectHelper;
|
||||
|
||||
protected String getClassifier()
|
||||
{
|
||||
return "tests";
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the JAR.
|
||||
*
|
||||
* @todo Add license files in META-INF directory.
|
||||
*/
|
||||
public void execute()
|
||||
throws MojoExecutionException
|
||||
{
|
||||
getLog().info( "Creating a jar containing the test classes for this project." );
|
||||
|
||||
File jarFile = createArchive();
|
||||
|
||||
projectHelper.attachArtifact( getProject(), "jar", "tests", jarFile );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the test-classes directory, to serve as the root of the tests jar.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue