Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… ·...

84
Apache Maven: Best Practices Wendy Smoak - [email protected] http://people.apache.org/~wsmoak/maven

Transcript of Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… ·...

Page 2: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Maven without the PAIN

2

Page 3: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Maven without the PAIN

Sometimes unpleasant

You know it’s for your own good!

Can avoid or alleviate the problems

2

Page 4: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

3

Who?

Brett Porter

Struts, Tiles, Shale, MyFaces,Maven, Continuum, Archiva

Wendy Smoak

Page 5: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

4

Page 6: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Getting Ready for Maven4

Page 7: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Why are you using Maven?

5

Page 8: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Why are you using Maven?Consider this from the beginning

Right tool for the job

Ensure you reap the benefits

5

Page 9: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Planning Ahead

6

Page 10: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Preparing Your Environment

Planning Ahead

6

Page 11: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Development Environment

7

Maven is best used in the bigger picture

Plan for the infrastructure you will use

Page 12: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Development Environment

7

Maven is best used in the bigger picture

Plan for the infrastructure you will use

<scm> <connection>... <developerConnection>... <url>...</scm>

<issueManagement> <url>... <system>...</issueManagement>

Page 13: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Maven is intended to be automated

More than continuous integration

Automated Build Servers

8

Page 14: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Repository Management

9

Page 15: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Repository ManagementCentralize storage of artifacts

Store the artifacts you buildStore third-party artifacts you consume

9

Page 16: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Repository ServersCan start with simple storage

Servers can help manage the artifacts

10

Page 17: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Using Repositories

11

<repository> <id>apache-snapshots</id> <name>Apache Snapshots Repository</name> <url>http://people.apache.org/repo/m2-snapshot-repository</url> <releases> <enabled>false</enabled> </releases></repository>

Page 18: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Using Repositories

11

<repository> <id>apache-snapshots</id> <name>Apache Snapshots Repository</name> <url>http://people.apache.org/repo/m2-snapshot-repository</url> <releases> <enabled>false</enabled> </releases></repository>

<repository> <id>java-net-m1</id> <name>Java.net Repository</name> <url>http://download.java.net/maven/1/</url> <layout>legacy</layout> <snapshots> <enabled>false</enabled> </snapshots></repository>

Page 19: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

<repository> <id>apache-snapshots</id> <name>Apache Snapshots Repository</name> <url>http://people.apache.org/repo/m2-snapshot-repository</url> <releases> <enabled>false</enabled> </releases></repository>

<repository> <id>java-net-m1</id> <name>Java.net Repository</name> <url>http://download.java.net/maven/1/</url> <layout>legacy</layout> <snapshots> <enabled>false</enabled> </snapshots></repository>

Using Repositories

12

Page 20: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

<repository> <id>apache-snapshots</id> <name>Apache Snapshots Repository</name> <url>http://people.apache.org/repo/m2-snapshot-repository</url> <releases> <enabled>false</enabled> </releases></repository>

<repository> <id>java-net-m1</id> <name>Java.net Repository</name> <url>http://download.java.net/maven/1/</url> <layout>legacy</layout> <snapshots> <enabled>false</enabled> </snapshots></repository>

<repository> <id>codehaus-snapshots</id> <name>Codehaus Snapshots Repository</name> <url>http://snapshots.repository.codehaus.org/</url> <releases> <enabled>false</enabled> </releases></repository>

<repository> <id>apache-releases</id> <name>Apache Releases Repository</name> <url>http://people.apache.org/repo/m2-ibiblio-rsync-repository</url> <snapshots> <enabled>false</enabled> </snapshots></repository>

<repository> <id>codehaus-releases</id> <name>Codehaus Releases Repository</name> <url>http://repository.codehaus.org/</url> <snapshots> <enabled>false</enabled> </snapshots></repository>

Using Repositories

12

<repository> <id>java-net-m2</id> <name>Java.net Repository</name> <url>http://download.java.net/maven/2/</url> <snapshots> <enabled>false</enabled> </snapshots></repository>

X

Page 21: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Using Repositories

13

Page 22: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Using RepositoriesMinimize the number of repositories

13

Page 23: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Using RepositoriesMinimize the number of repositories

Only in the POM if you redistribute

13

Page 24: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Using RepositoriesMinimize the number of repositories

Only in the POM if you redistribute

Use repository manager to centralize

13

Page 25: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Locking Down

14

<mirrors> <mirror> <id>archiva-snapshots-apache</id> <url>http://reposerver/archiva/repository/snapshots/</url> <mirrorOf>apache.snapshots</mirrorOf> </mirror> <mirror> <id>archiva-snapshots-codehaus</id> <url>http://reposerver/archiva/repository/snapshots/</url> <mirrorOf>codehaus.snapshots</mirrorOf> </mirror> ... <mirror> <id>archiva-default</id> <url>http://reposerver/archiva/repository/internal/</url> <mirrorOf>*</mirrorOf> </mirror></mirrors>

Page 26: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Settings and InstallationThree levels of configuration

project (pom.xml)user (~/.m2/settings.xml)installation (<maven>/conf/settings.xml)

15

Page 27: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Keeping it Simple

16

Page 28: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Creating New Projects

Keeping it Simple

16

Page 29: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

ArchetypesCreate new projects quickly

Standard project layouts

Include organizational POM

Facilitates consistency

17

Page 30: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Writing the POM

18

Page 31: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Writing the POM

18

Write the build like you write code

Page 32: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Writing the POM

18

Write the build like you write code

Utilize conventions

Page 33: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Writing the POM

18

Write the build like you write code

Utilize conventions

Use multiple modules

Page 34: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Inheritance

19

Page 35: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

InheritanceMulti-module inheritance<parent> <groupId>org.apache.maven</groupId> <artifactId>maven</artifactId> <version>2.1-SNAPSHOT</version></parent><artifactId>maven-core</artifactId>

19

Page 36: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

InheritanceMulti-module inheritance<parent> <groupId>org.apache.maven</groupId> <artifactId>maven</artifactId> <version>2.1-SNAPSHOT</version></parent><artifactId>maven-core</artifactId>

Organisational POM hierarchy<parent> <groupId>org.apache</groupId> <artifactId>apache</artifactId> <version>3</version></parent><groupId>org.apache.maven</groupId><artifactId>maven</artifactId><version>2.1-SNAPSHOT</version>

19

Page 37: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

DependenciesSpecify only what you need

Specify scope

Use dependencyManagement to:coerce Maven to use a particular versionenforce consistency within a project

20

Page 38: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Build Pipeline

21

Page 39: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Build PipelineDepends on your team

21

Page 40: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Build PipelineDepends on your team

Use profiles for controlling complexity

21

Page 41: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Build PipelineDepends on your team

Use profiles for controlling complexity

Applies to testing as well

21

Page 42: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Build PipelineDepends on your team

Use profiles for controlling complexity

Applies to testing as well

Key is to keep the build fast

21

Page 43: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Build PipelineDepends on your team

Use profiles for controlling complexity

Applies to testing as well

Key is to keep the build fast

21

Page 44: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

22

Scripting

Page 45: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

22

ScriptingMaven is declarative by design

Page 46: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

22

ScriptingMaven is declarative by design

Integrate scripting if necessary

Page 47: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

22

ScriptingMaven is declarative by design

Integrate scripting if necessary

Consider writing plugins

Page 48: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

The D Word

23

Page 49: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Documenting as You Go

The D Word

23

Page 50: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

DocumentationDocument the build

Developer documentation

separate from product documentationkeep it together with reports

24

Page 51: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Sites and ReportsA whole other topic of best practices!

But apply the same principles

set up what you’ll actually useset up enforcement checks, not just reports

25

Page 52: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Portability

26

Page 53: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Playing well with others

Portability

26

Page 54: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

The Goal

27

Page 55: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

The Goal

27

When a new developer builds the project

it works first go... and it keeps working

Page 56: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

28

Page 57: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

28

maven.test.skipis evil

Page 58: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Hard CodingDon’t hard code paths

Don’t hard code databases

Don’t hard code properties

Don’t do it in the tests either

29

Page 59: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

ProfilesVery useful - but don’t abuse them

Document them all

Avoid depending on the environment

30

Page 60: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Portable Artifacts

31

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="org.hsqldb.jdbcDriver" /> <property name="url" value="jdbc:hsqldb:database" /> <property name="username" value="sa" /> <property name="password" value="" /></bean>

Page 61: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Portable Artifacts

31

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="org.hsqldb.jdbcDriver" /> <property name="url" value="jdbc:hsqldb:database" /> <property name="username" value="sa" /> <property name="password" value="" /></bean> X

Page 62: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Portable Artifacts

31

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="org.hsqldb.jdbcDriver" /> <property name="url" value="jdbc:hsqldb:database" /> <property name="username" value="sa" /> <property name="password" value="" /></bean> Xvalue="org.hsqldb.jdbcDriver"

value="jdbc:hsqldb:database"

Page 63: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Portable ArtifactsArtifacts in repository must be unique

Either by classifier, or being portable

Recommend externalising configurationdatabasetarget environmentproperties

32

Page 64: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

}${Resource Filtering

33

Page 65: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

}${Resource Filtering

Use with great care!

33

Page 66: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

}${Resource Filtering

Use with great care!

Centralization, not substitution✓ google.analytics.code=UA-1234567-1X database.password=reallysecretpword

33

Page 67: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

}${Resource Filtering

Use with great care!

Centralization, not substitution✓ google.analytics.code=UA-1234567-1X database.password=reallysecretpword

Useful for once-off alterations

33

Page 68: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

}${Resource Filtering

Use with great care!

Centralization, not substitution✓ google.analytics.code=UA-1234567-1X database.password=reallysecretpword

Useful for once-off alterations

Consider externalizing configuration

33

Page 69: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Shared ResourcesDon’t duplicate resources across projects

ZIP and put in the repository

Use the dependency plugin to retrieve

34

Page 70: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Reproducibility

35

Page 71: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Ensuring Reproducible Builds

Reproducibility

35

Page 72: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Reproducibility

36

Page 73: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Reproducibility

36

Important for releases

Page 74: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Reproducibility

36

Important for releases

More important for source releases

Page 75: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Reproducibility

36

Important for releases

More important for source releases

Build must be isolated from change

Page 76: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Reproducibility

36

Important for releases

More important for source releases

Build must be isolated from change

Portability is a pre-requisite

Page 77: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

The Enforcer

37

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <version>1.0-alpha-4</version> <executions> <execution> <goals> <goal>enforce</goal> </goals> <configuration> <rules> <requirePluginVersions> <banLatest>true</banLatest> <banRelease>true</banRelease> </requirePluginVersions> </rules> </configuration> ...

Page 78: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

The Enforcer

38

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <version>1.0-alpha-4</version> <executions> <execution> <goals> <goal>enforce</goal> </goals> <configuration> <rules> <requirePluginVersions> <banLatest>true</banLatest> <banRelease>true</banRelease> </requirePluginVersions> </rules> </configuration> ...

Page 79: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

The Enforcer

38

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <version>1.0-alpha-4</version> <executions> <execution> <goals> <goal>enforce</goal> </goals> <configuration> <rules> <requirePluginVersions> <banLatest>true</banLatest> <banRelease>true</banRelease> </requirePluginVersions> </rules> </configuration> ...

<rules> <requirePluginVersions> <banLatest>true</banLatest> <banRelease>true</banRelease> </requirePluginVersions></rules>

Page 80: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

The EnforcerHelp ensure build will be reproducible

Based on rulesforce specific plugin versionsban snapshotsglobal exclusionsforce Maven/Java/OS versioncan write your own

39

Page 81: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Releasing

40

Page 82: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

Release Early, Often and Right

Releasing

40

Page 83: Apache Maven: Best Practicespeople.apache.org/~wsmoak/maven/ApacheMavenBestPractices-ACE… · Apache Maven: Best Practices Wendy Smoak - wsmoak@apache.org wsmoak/maven. Maven without

ReleasesSet the project version to a -SNAPSHOT

Make them early and often

Use Maven tools to automate

41