20
Practices Bes t

Ignite talk: Maven Best Practices

  • Upload
    tricode

  • View
    524

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Ignite talk: Maven Best Practices

PracticesBest

Page 2: Ignite talk: Maven Best Practices

${artifactId}

${pom.artifactId}${project.artifactId}

${project.build.sourceDirectory}

vs

Page 3: Ignite talk: Maven Best Practices

<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>

Page 4: Ignite talk: Maven Best Practices

<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>

Page 5: Ignite talk: Maven Best Practices

parent

application

module

knows of extends of

/project/pom.xml

/project/parent/pom.xml

/project/module1/pom.xml/project/module2/pom.xml

3typesofPOMs

Page 6: Ignite talk: Maven Best Practices

parent

application

module

knows of extends of

/project/pom.xml

/project/parent/pom.xml

/project/module1/pom.xml/project/module2/pom.xml

3typesofPOMs

Page 7: Ignite talk: Maven Best Practices

parentPOM

sho

uld know

nothingabout

the applicationmodulesand its

Page 8: Ignite talk: Maven Best Practices

<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

Page 9: Ignite talk: Maven Best Practices

<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

Page 10: Ignite talk: Maven Best Practices

<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

Page 11: Ignite talk: Maven Best Practices

<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

Page 12: Ignite talk: Maven Best Practices

<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

Page 13: Ignite talk: Maven Best Practices

<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

Page 14: Ignite talk: Maven Best Practices

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>

Page 15: Ignite talk: Maven Best Practices

applicationPOM

shouldworkwithout

specifingany

profile! $ mvn clean verify…[INFO] BUILD SUCCESS

Page 16: Ignite talk: Maven Best Practices

Make

use

DO NOT

buildsdependable

versioned artifactsSNAPSHOT

OT

Page 17: Ignite talk: Maven Best Practices

one artifactto rule all

DO NOT

OTcreate

specific artifactsenvironment

environments

environment specifics is configuration!

Page 18: Ignite talk: Maven Best Practices

clean POM

==clean & smaller

artifacts

faster builds==

mvn help:effective-pommvn dependency:analyze

Page 19: Ignite talk: Maven Best Practices

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

Page 20: Ignite talk: Maven Best Practices

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