Puppet Class: maven::maven

Defined in:
manifests/maven.pp

Overview

Class: maven::maven

A puppet recipe to install Apache Maven

Parameters:

- $version:
      Maven version.

Requires:

Java package installed.

Sample Usage:

class {'maven::maven':
  version => "3.0.5",
}

Parameters:

  • version (Any) (defaults to: '3.0.5')
  • repo (Any) (defaults to: { #url => 'http://repo1.maven.org/maven2', #username => '', #password => '', })


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'manifests/maven.pp', line 31

class maven::maven(
  $version = '3.0.5',
  $repo = {
    #url      => 'http://repo1.maven.org/maven2',
    #username => '',
    #password => '',
  } ) {

  $archive = "/tmp/apache-maven-${version}-bin.tar.gz"

  # Avoid redownloading when tmp tar.gz is deleted
  if $::maven_version != $version {

    # we could use puppet-stdlib function !empty(repo) but avoiding adding a new
    # dependency for now
    if "x${repo['url']}x" != 'xx' {
      wget::authfetch { 'fetch-maven':
        source      => "${repo['url']}/org/apache/maven/apache-maven/$version/apache-maven-${version}-bin.tar.gz",
        destination => $archive,
        user        => $repo['username'],
        password    => $repo['password'],
        before      => Exec['maven-untar'],
      }
    } else {
      wget::fetch { 'fetch-maven':
        source      => "http://archive.apache.org/dist/maven/binaries/apache-maven-${version}-bin.tar.gz",
        destination => $archive,
        before      => Exec['maven-untar'],
      }
    }
    exec { 'maven-untar':
      command => "tar xf /tmp/apache-maven-${version}-bin.tar.gz",
      cwd     => '/opt',
      creates => "/opt/apache-maven-${version}",
      path    => ['/bin','/usr/bin'],
    }

    file { '/usr/bin/mvn':
      ensure  => link,
      target  => "/opt/apache-maven-${version}/bin/mvn",
      require => Exec['maven-untar'],
    } ->
    file { '/usr/local/bin/mvn':
      ensure  => absent,
    }
  }
}