Upload
tricode
View
524
Download
0
Tags:
Embed Size (px)
Citation preview
PracticesBest
${artifactId}
${pom.artifactId}${project.artifactId}
${project.build.sourceDirectory}
vs
<project> <groupId>my.group</groupId> <artifactId>parent</artifactId> <version>1.0.0</version> <properties> <baseId>cool-project</baseId> </properties></project>
<project> <parent> <groupId>my.group</groupId> <artifactId>parent</artifactId> <version>1.0.0</version> </parent> <artifactId>${baseId}-extra</artifactId></project>
<project> <groupId>my.group</groupId> <artifactId>parent</artifactId> <version>1.0.0</version> <properties> <baseId>cool-project</baseId> <globalVersion>4.3.2</globalVersion> </properties></project>
<project> <parent> <groupId>my.group</groupId> <artifactId>parent</artifactId> <version>1.0.0</version> </parent> <artifactId>${baseId}-extra</artifactId> <properties> <baseId>cool-project</baseId> <globalVersion>9.2.1</globalVersion> </properties></project>
parent
application
module
knows of extends of
/project/pom.xml
/project/parent/pom.xml
/project/module1/pom.xml/project/module2/pom.xml
3typesofPOMs
parent
application
module
knows of extends of
/project/pom.xml
/project/parent/pom.xml
/project/module1/pom.xml/project/module2/pom.xml
3typesofPOMs
parentPOM
sho
uld know
nothingabout
the applicationmodulesand its
<project> <groupId>my.group</groupId> <artifactId>parent</artifactId> <version>1.0.0</version> <packaging>pom</packaging>
<build> <pluginManagement/> </build> <ciManagement/> <contributors/> <developers/> <dependencyManagement/> <distributionManagement/> <inceptionYear/> <issueManagement/> <licenses/> <mailingLists/> <name/> <organization/> <prerequisites/> <properties/> <scm/> <url/></project>
parent POM
definesenvironmentfor
modulePOMs
<project> <groupId>my.group</groupId> <artifactId>parent</artifactId> <version>1.0.0</version> <packaging>pom</packaging>
<build> <pluginManagement/> </build> <ciManagement/> <contributors/> <developers/> <dependencyManagement/> <distributionManagement/> <inceptionYear/> <issueManagement/> <licenses/> <mailingLists/> <name/> <organization/> <prerequisites/> <properties/> <scm/> <url/></project>
parent POM
definesenvironmentfor
modulePOMs
<project> ... <dependencyManagement> <dependencies> <dependency> <!-- Required --> <groupId>my.depend</groupId> <artifactId>application-api</artifactId> <version>${depend.version}</version>
<!-- Only when non-default --> <classifier></classifier> <type></type>
<!-- Don't do it --> <exclusions/> <optional/> <scope/> </dependency> </dependencies> </dependencyManagement> ...</project>
parentPOM
<project> ... <build> <pluginManagement> <plugins> <plugin> <!-- Required --> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <version>2.7</version>
<!-- Don't do it --> <configuration/> <dependencies/> <executions/> <extensions/> <goals/> <inherited/> </plugin> </plugins> </pluginManagement> </build> ...</project>
parentPOM
<project> <parent> <groupId>my.group</groupId> <artifactId>parent</artifactId> <version>1.0.0</version> <relativePath>../parent/pom.xml</relativePath> <parent> <artifactId>module1</artifactId> <packaging>jar</packaging>
<dependencies/> <build> <plugins/> </build>
<contributors/> <developers/> <name/>
<!-- Avoid when possible --> <profiles/></project>
modulePOM
<project> <parent/> <artifactId>module1</artifactId> <packaging>jar</packaging>
<dependencies> <dependency> <groupId>my.depend</groupId> <artifactId>application-api</artifactId> <!-- Don't do it --> <version>${depend.version}</version> </dependency> </dependencies>
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <!-- Don't do it --> <version>2.7</version> </plugin> </plugins> </build> ...</project>
modulePOM
applicationPOM
<project> <groupId>my.group</groupId> <artifactId>application</artifactId> <version>1.0.0</version> <packaging>pom</packaging> <modules> <module>parent</module> <module>module1</module> </modules>
<build> <plugins/> </build>
<contributors/> <developers/> <distributionManagement/> <name/> <profiles/> <scm/>
<!-- Don't do it --> <dependencies/></project>
applicationPOM
shouldworkwithout
specifingany
profile! $ mvn clean verify…[INFO] BUILD SUCCESS
Make
use
DO NOT
buildsdependable
versioned artifactsSNAPSHOT
OT
one artifactto rule all
DO NOT
OTcreate
specific artifactsenvironment
environments
environment specifics is configuration!
clean POM
==clean & smaller
artifacts
faster builds==
mvn help:effective-pommvn dependency:analyze
Summary (1)
1. Don't use deprecated references
2. Try to avoid using inherited properties
3. Variables in POM files are processed after inheritance
4. Set dependencyManagement in the parent POM to define all dependency versions without scope
5. Use properties to define the dependency versions
6. Do not use SNAPSHOT versioned artifacts
Summary (2)
7. Do not create environment specific artifacts
8. Set pluginManagement in the parent POM to define versions for all plugins (incl. standard Maven plugins)
9. Use the relativePath tag to point to parent pom.xml
10. Keep POMs clean (use mvn help:effective-pom and mvn dependency:analyze)
11. distributionManagement and scm configuration in the POM, repositories and pluginRepositories in Maven settings.xml
12. Build must pass when no profile has been activated