Package org.apache.maven.plugins.jar
Class AbstractJarMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- org.apache.maven.plugins.jar.AbstractJarMojo
-
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled
,org.apache.maven.plugin.Mojo
- Direct Known Subclasses:
JarMojo
,TestJarMojo
public abstract class AbstractJarMojo extends org.apache.maven.plugin.AbstractMojo
Base class for creating a jar from project classes.- Version:
- $Id$
-
-
Field Summary
Fields Modifier and Type Field Description private org.apache.maven.archiver.MavenArchiveConfiguration
archive
The archive configuration to use.private java.util.Map<java.lang.String,org.codehaus.plexus.archiver.Archiver>
archivers
The Jar archiver.private static java.lang.String[]
DEFAULT_EXCLUDES
private static java.lang.String[]
DEFAULT_INCLUDES
private java.lang.String[]
excludes
List of files to exclude.private java.lang.String
finalName
Name of the generated JAR.private boolean
forceCreation
Require the jar plugin to build a new JAR even if none of the contents appear to have changed.private java.lang.String[]
includes
List of files to include.private static java.lang.String
MODULE_DESCRIPTOR_FILE_NAME
private java.io.File
outputDirectory
Directory containing the generated JAR.private java.lang.String
outputTimestamp
Timestamp for reproducible output archive entries, either formatted as ISO 8601 extended offset date-time (e.g.private org.apache.maven.project.MavenProject
project
The {@link {MavenProject}.private org.apache.maven.project.MavenProjectHelper
projectHelper
private org.apache.maven.execution.MavenSession
session
TheMavenSession
.private boolean
skipIfEmpty
Skip creating empty archives.private boolean
useDefaultManifestFile
Deprecated.For version 3.0.0 this parameter is only defined here to break the build if you use it!
-
Constructor Summary
Constructors Constructor Description AbstractJarMojo()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.io.File
createArchive()
Generates the JAR.void
execute()
Generates the JAR.protected abstract java.io.File
getClassesDirectory()
Return the specific output directory to serve as the root for the archive.protected abstract java.lang.String
getClassifier()
Overload this to produce a jar with another classifier, for example a test-jar.private java.lang.String[]
getExcludes()
private java.lang.String[]
getIncludes()
protected java.io.File
getJarFile(java.io.File basedir, java.lang.String resultFinalName, java.lang.String classifier)
Returns the Jar file to generate, based on an optional classifier.protected org.apache.maven.project.MavenProject
getProject()
protected abstract java.lang.String
getType()
Overload this to produce a test-jar, for example.protected boolean
hasClassifier()
private boolean
projectHasAlreadySetAnArtifact()
-
-
-
Field Detail
-
DEFAULT_EXCLUDES
private static final java.lang.String[] DEFAULT_EXCLUDES
-
DEFAULT_INCLUDES
private static final java.lang.String[] DEFAULT_INCLUDES
-
MODULE_DESCRIPTOR_FILE_NAME
private static final java.lang.String MODULE_DESCRIPTOR_FILE_NAME
- See Also:
- Constant Field Values
-
includes
@Parameter private java.lang.String[] includes
List of files to include. Specified as fileset patterns which are relative to the input directory whose contents is being packaged into the JAR.
-
excludes
@Parameter private java.lang.String[] excludes
List of files to exclude. Specified as fileset patterns which are relative to the input directory whose contents is being packaged into the JAR.
-
outputDirectory
@Parameter(defaultValue="${project.build.directory}", required=true) private java.io.File outputDirectory
Directory containing the generated JAR.
-
finalName
@Parameter(defaultValue="${project.build.finalName}", readonly=true) private java.lang.String finalName
Name of the generated JAR.
-
archivers
@Component private java.util.Map<java.lang.String,org.codehaus.plexus.archiver.Archiver> archivers
The Jar archiver.
-
project
@Parameter(defaultValue="${project}", readonly=true, required=true) private org.apache.maven.project.MavenProject project
The {@link {MavenProject}.
-
session
@Parameter(defaultValue="${session}", readonly=true, required=true) private org.apache.maven.execution.MavenSession session
TheMavenSession
.
-
archive
@Parameter private org.apache.maven.archiver.MavenArchiveConfiguration archive
The archive configuration to use. See Maven Archiver Reference.
-
useDefaultManifestFile
@Parameter(property="jar.useDefaultManifestFile", defaultValue="false") private boolean useDefaultManifestFile
Deprecated.For version 3.0.0 this parameter is only defined here to break the build if you use it!Using this property will fail your build cause it has been removed from the plugin configuration. See the Major Version Upgrade to version 3.0.0 for the plugin.
-
projectHelper
@Component private org.apache.maven.project.MavenProjectHelper projectHelper
-
forceCreation
@Parameter(property="maven.jar.forceCreation", defaultValue="false") private boolean forceCreation
Require the jar plugin to build a new JAR even if none of the contents appear to have changed. By default, this plugin looks to see if the output jar exists and inputs have not changed. If these conditions are true, the plugin skips creation of the jar. This does not work when other plugins, like the maven-shade-plugin, are configured to post-process the jar. This plugin can not detect the post-processing, and so leaves the post-processed jar in place. This can lead to failures when those plugins do not expect to find their own output as an input. Set this parameter to true to avoid these problems by forcing this plugin to recreate the jar every time.
Starting with 3.0.0 the property has been renamed fromjar.forceCreation
tomaven.jar.forceCreation
.
-
skipIfEmpty
@Parameter(defaultValue="false") private boolean skipIfEmpty
Skip creating empty archives.
-
outputTimestamp
@Parameter(defaultValue="${project.build.outputTimestamp}") private java.lang.String outputTimestamp
Timestamp for reproducible output archive entries, either formatted as ISO 8601 extended offset date-time (e.g. in UTC such as '2011-12-03T10:15:30Z' or with an offset '2019-10-05T20:37:42+06:00'), or as an int representing seconds since the epoch (like SOURCE_DATE_EPOCH).- Since:
- 3.2.0
-
-
Method Detail
-
getClassesDirectory
protected abstract java.io.File getClassesDirectory()
Return the specific output directory to serve as the root for the archive.- Returns:
- get classes directory.
-
getProject
protected final org.apache.maven.project.MavenProject getProject()
- Returns:
- the
project
-
getClassifier
protected abstract java.lang.String getClassifier()
Overload this to produce a jar with another classifier, for example a test-jar.- Returns:
- get the classifier.
-
getType
protected abstract java.lang.String getType()
Overload this to produce a test-jar, for example.- Returns:
- return the type.
-
getJarFile
protected java.io.File getJarFile(java.io.File basedir, java.lang.String resultFinalName, java.lang.String classifier)
Returns the Jar file to generate, based on an optional classifier.- Parameters:
basedir
- the output directoryresultFinalName
- the name of the ear fileclassifier
- an optional classifier- Returns:
- the file to generate
-
createArchive
public java.io.File createArchive() throws org.apache.maven.plugin.MojoExecutionException
Generates the JAR.- Returns:
- The instance of File for the created archive file.
- Throws:
org.apache.maven.plugin.MojoExecutionException
- in case of an error.
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException
Generates the JAR.- Throws:
org.apache.maven.plugin.MojoExecutionException
- in case of an error.
-
projectHasAlreadySetAnArtifact
private boolean projectHasAlreadySetAnArtifact()
-
hasClassifier
protected boolean hasClassifier()
- Returns:
- true in case where the classifier is not
null
and contains something else than white spaces.
-
getIncludes
private java.lang.String[] getIncludes()
-
getExcludes
private java.lang.String[] getExcludes()
-
-