Skip to content

Latest commit

 

History

History
128 lines (100 loc) · 2.38 KB

maven.md

File metadata and controls

128 lines (100 loc) · 2.38 KB

Maven

Common tasks and activities

  • Multiple jars
  • Dependencies and versions
  • Project structure
  • Building, publishing and deploying

Archetype Info

  • create directory structure

Dependency Info

What Maven Do

Maven Repository

Project Template (Archetype)

  1. create an archetype
$ archetype:generate
  • Group ID:
  • Artifact ID:
  • Version:
  • Package:
The pom.xml file
  • Maven co-ordinates
  • Metadata
  • Build information
  • Resources and Dependencies
	<groupId></groupId>
	<artifactId></artifactId>
	<version></version>
	<packaging></packaging>

	<name></name>
	<url></url>

	<!-- when to use the dependency -->
	<dependencies>
		<dependency>
			<scope></scope>
		</dependency>
	<dependencies>
  • scope: in which phase the dependency is available
Source Folder

It is important to setup the source directory so that IDE will look for source code files.

<build>
  <sourceDirectory>../src/main/java</sourceDirectory>
  <plugins>
    <plugin>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.3</version>
      <configuration>
        <!-- only look for 
        <includes><include>**/core/**</include></includes>
      </configuration>
    </plugin>
  </plugins>
</build>

In this example, the sources are found in the parent directory ../src/main/java, and only Java files within a core package are included.

Maven Build (compile and package)

  • Previous phases need to be run successfully in order to run current phase.
Build Lifecycle Phases
  • validate

  • compile

  • test

  • package

  • install: publish an artifect to a local maven repository.

  • deploy: publish an artifect to remote maven repository.

  • clean: remove all jobs have been done. (e.g. remove target folder)

Maven Plugins

  • We provide plugin block in pom.xml to overwrite default configuration.
pom.xml

<build>
	<plugins>
		<plugin>
			<groupId></groupId>
			<artifactId></artifactId>
			<version></version>
			<configuration></configuration>
		</plugin>
	</plugins>
</build>
  • To use plugin
$ mvn plugin_name:supported_command
Maven-compiler-plugin
<!-- config compiler version -->
<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-compiler-plugin</artifactId>
	<version>2.0.2</version>
	<configuration>
		<source>1.4</source>
		<target>1.4</target>
	</configuration>
</plugin>