Package org.codehaus.mojo.flatten
Class FlattenMojo
java.lang.Object
org.apache.maven.plugin.AbstractMojo
org.codehaus.mojo.flatten.AbstractFlattenMojo
org.codehaus.mojo.flatten.FlattenMojo
- All Implemented Interfaces:
ContextEnabled
,Mojo
@Mojo(name="flatten",
requiresDependencyCollection=RUNTIME,
threadSafe=true)
public class FlattenMojo
extends AbstractFlattenMojo
This MOJO realizes the goal
flatten
that generates the flattened POM and potentially updates the POM file
so that the current MavenProject
's file
points to the flattened POM instead of the original pom.xml
file. The flattened POM is a reduced version
of the original POM with the focus to contain only the important information for consuming it. Therefore information
that is only required for maintenance by developers and to build the project artifact(s) are stripped. Starting from
here we specify how the flattened POM is created from the original POM and its project:Element | Transformation | Note |
---|---|---|
modelVersion |
Fixed to "4.0.0" | New maven versions will once be able to evolve the model version without incompatibility to older versions if flattened POMs get deployed. |
groupId artifactId version packaging |
resolved | copied to the flattened POM but with inheritance from parent as well as with all
variables and defaults resolved. These elements are technically required for consumption. |
licenses |
resolved | copied to the flattened POM but with inheritance from parent as well as with all
variables and defaults resolved. The licenses would not be required in flattened POM. However, they make sense for
publication and deployment and are important for consumers of your artifact. |
dependencies |
resolved specially | flattened POM contains the actual dependencies of the project. Test dependencies are removed. Variables and
dependencyManagement is resolved to get fixed dependency attributes
(especially version ). If embedBuildProfileDependencies is set to true , then also build-time driven Profile s will be
evaluated and may add dependencies . For further details see Profile s below. |
profiles |
resolved specially | only the Activation and the dependencies of a Profile are copied to the
flattened POM. If you set the parameter embedBuildProfileDependencies to
true then only profiles activated by JDK or
OS will be added to the flattened POM while the other profiles are triggered by the
current build setup and if activated their impact on dependencies is embedded into the resulting flattened POM. |
name description url inceptionYear organization scm developers contributors mailingLists pluginRepositories issueManagement ciManagement distributionManagement |
configurable | Will be stripped from the flattened POM by default. You can configure all of the listed elements inside
pomElements that should be kept in the flattened POM (e.g.
<pomElements><name/><description/><developers/><contributors/></pomElements>). For common use-cases there are
predefined modes available via the parameter flattenMode that should be used in preference. |
prerequisites |
configurable | Like above but by default NOT removed if packaging is "maven-plugin". |
repositories |
configurable | Like two above but by default NOT removed. If you want have it removed, you need to use the parameter
pomElements and configure the child element repositories with value flatten .
|
parent build dependencyManagement properties modules reporting |
configurable | These elements should typically be completely stripped from the flattened POM. However for ultimate flexibility
(e.g. if you only want to resolve variables in a POM with packaging pom) you can also configure to keep these
elements. We strictly recommend to use this feature with extreme care and only if packaging is pom (for "Bill of
Materials"). In the latter case you configure the parameter flattenMode to the value
bom .If the build element contains plugins in the build/plugins section which are configured to
load extensions, a reduced build element
containing these plugins will be kept in the flattened pom. |
- Author:
- Joerg Hohwiller (hohwille at users.sourceforge.net)
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Model
createCleanPomImpl
(Model effectivePom) protected Model
createEffectivePomImpl
(ModelBuildingRequest buildingRequest) Creates the effective POM for the givenpomFile
trying its best to match the core maven behaviour.protected List
<Dependency> createFlattenedDependencies
(Model effectiveModel) Creates theList
ofdependencies
for the flattened POM.protected void
createFlattenedDependencies
(Model effectiveModel, List<Dependency> flattenedDependencies) Collects the resolveddependencies
from the giveneffectiveModel
.protected Dependency
createFlattenedDependency
(Dependency projectDependency) protected Model
createFlattenedPom
(File pomFile) This method creates the flattened POM what is the main task of this plugin.protected static List
<Repository> createFlattenedRepositories
(List<Repository> repositories) Creates a flattenedList
ofRepository
elements where those from super-POM are omitted.void
execute()
protected String
extractHeaderComment
(File xmlFile) This method extracts the XML header comment if available.protected static boolean
isBuildTimeDriven
(Activation activation) boolean
boolean
protected boolean
protected void
writePom
(Model pom, File pomFile, String headerComment, org.codehaus.mojo.flatten.KeepCommentsInPom anOriginalCommentsPath) protected void
writeStringToFile
(String data, File file, String encoding) Writes the givendata
to the givenfile
using the specifiedencoding
.Methods inherited from class org.codehaus.mojo.flatten.AbstractFlattenMojo
getFlattenedPomFile, getFlattenedPomFilename, getOutputDirectory, shouldSkip
Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Constructor Details
-
FlattenMojo
public FlattenMojo()The constructor.
-
-
Method Details
-
execute
-
shouldSkipGoal
protected boolean shouldSkipGoal()- Specified by:
shouldSkipGoal
in classAbstractFlattenMojo
-
extractHeaderComment
This method extracts the XML header comment if available.- Parameters:
xmlFile
- is the XMLFile
to parse.- Returns:
- the XML comment between the XML header declaration and the root tag or
null
if NOT available. - Throws:
MojoExecutionException
- if anything goes wrong.
-
writePom
protected void writePom(Model pom, File pomFile, String headerComment, org.codehaus.mojo.flatten.KeepCommentsInPom anOriginalCommentsPath) throws MojoExecutionException - Parameters:
pom
- theModel
of the POM to write.pomFile
- theFile
where to write the given POM will be written to.Parent directories
arecreated
automatically.headerComment
- is the content of a potential XML comment at the top of the XML (after XML declaration and before root tag). May benull
if not present and to be omitted in target POM.- Throws:
MojoExecutionException
- if the operation failed (e.g. due to anIOException
).
-
writeStringToFile
protected void writeStringToFile(String data, File file, String encoding) throws MojoExecutionException Writes the givendata
to the givenfile
using the specifiedencoding
.- Parameters:
data
- is theString
to write.file
- is theFile
to write to.encoding
- is the encoding to use for writing the file.- Throws:
MojoExecutionException
- if anything goes wrong.
-
createFlattenedPom
protected Model createFlattenedPom(File pomFile) throws MojoExecutionException, MojoFailureException This method creates the flattened POM what is the main task of this plugin.- Parameters:
pomFile
- is the name of the original POM file to read and transform.- Returns:
- the
Model
of the flattened POM. - Throws:
MojoExecutionException
- if anything goes wrong (e.g. POM can not be processed).MojoFailureException
- if anything goes wrong (logical error).
-
createCleanPomImpl
This method creates the clean POM as aModel
where to copy elements from that shall beflattened
. Will be mainly empty but contains some the minimum elements that have to be kept in flattened POM.- Parameters:
effectivePom
- is the effective POM.- Returns:
- the clean POM.
- Throws:
MojoExecutionException
- if anything goes wrong.
-
createFlattenedRepositories
Creates a flattenedList
ofRepository
elements where those from super-POM are omitted.- Parameters:
repositories
- is theList
ofRepository
elements. May benull
.- Returns:
- the flattened
List
ofRepository
elements ornull
ifnull
was given.
-
createEffectivePomImpl
protected Model createEffectivePomImpl(ModelBuildingRequest buildingRequest) throws MojoExecutionException Creates the effective POM for the givenpomFile
trying its best to match the core maven behaviour.- Parameters:
buildingRequest
-ModelBuildingRequest
- Returns:
- the parsed and calculated effective POM.
- Throws:
MojoExecutionException
- if anything goes wrong.
-
isEmbedBuildProfileDependencies
public boolean isEmbedBuildProfileDependencies()- Returns:
true
if build-dependent profiles (triggered by OS or JDK) should be evaluated and their effect (variables and dependencies) are resolved and embedded into the flattened POM while the profile itself is stripped. Otherwise iffalse
the profiles will remain untouched.
-
isBuildTimeDriven
- Parameters:
activation
- is theActivation
of aProfile
.- Returns:
true
if the givenActivation
is build-time driven,false
otherwise (if it is triggered by OS or JDK).
-
createFlattenedDependencies
protected List<Dependency> createFlattenedDependencies(Model effectiveModel) throws MojoExecutionException Creates theList
ofdependencies
for the flattened POM. These are all resolveddependencies
except for those added fromprofiles
.- Parameters:
effectiveModel
- is the effective POMModel
to process.- Returns:
- the
List
ofdependencies
. - Throws:
MojoExecutionException
- if anything goes wrong.
-
createFlattenedDependencies
protected void createFlattenedDependencies(Model effectiveModel, List<Dependency> flattenedDependencies) throws MojoExecutionException Collects the resolveddependencies
from the giveneffectiveModel
.- Parameters:
effectiveModel
- is the effective POMModel
to process.flattenedDependencies
- is theList
where to add the collecteddependencies
.- Throws:
MojoExecutionException
- if anything goes wrong.
-
createFlattenedDependency
- Parameters:
projectDependency
- is the projectDependency
.- Returns:
- the flattened
Dependency
ornull
if the givenDependency
is NOT relevant for flattened POM.
-
isUpdatePomFile
public boolean isUpdatePomFile()- Returns:
true
if the generated flattened POM shall beset
as POM artifact of theMavenProject
,false
otherwise.
-