Maven's (eight) convention is better than configuration

Source: Internet
Author: User

MAVEN's configuration file looks complicated, but it only needs to set up a few individual configuration items based on the actual background of the project. MAVEN has its own set of default configurations, and users do not need to modify the agreed content unless necessary. This is called the "Convention is better than the configuration".

File directory

The default file storage structure for MAVEN is as follows:

Each stage of the task knows how to properly complete their work, such as compile task will know from Src/main/java compiled all the Java files, and its output class file stored in target/classes.

For MAVEN, adopting a "contract better than configuration" strategy can reduce the amount of configuration work, reduce the cost of learning, and more importantly, introduce a unified specification to the project.

Version specification

MAVEN has its own version specification, which is generally defined as follows:

<majorversion>.<minor Version>.<incremental Version>-<qualifier>

Like 1.2.3-beta-01. To illustrate, Maven's own judgment version of the algorithm is the major,minor,incremental part with a number comparison, qualifier part with a string comparison, so be careful alpha-2 and alpha-15 comparative relationship, the most useful The format of the alpha-02.

Maven can use several special string SNAPSHOT, LATEST, release when versioning. such as "1.0-snapshot". The meanings and processing logic of each part are explained below:

L SNAPSHOT

If a version contains the string "SNAPSHOT", Maven expands the symbol to a date and time value, converted to UTC time, when the component is installed or released. For example, "1.0-snapshot" will become 1.0-20100505-141000-1 when it is released on May 5, 2010 2:10 P.M..

This word can only be used in the development process, because in general, the project team will frequently release some versions, finally, when the actual release, will be in these snapshot version of the search for a stable, for the official release, For example, before the release of the 1.4 release, there will be a series of 1.4-snapshot, and the actual release of 1.4, is also a stable version from it.

L LATEST

Refers to the latest release of a particular artifact, which may be a release or a snapshot version, depending on which time is last.

L RELEASE

Refers to the last released version.

Maven variable

In addition to constants defined with properties in Setting.xml and Pom.xml, MAVEN also provides some implicit variables for accessing system environment variables.

Category

Example

Built-in properties

${basedir} represents the project root directory, which is the directory containing the Pom.xml file

${version} indicates the project version

${project.basedir} with ${basedir}

${project.baseuri} indicates the project file address

${maven.build.timestamp} indicates the project artifact start time

Setting property

${settings.localrepository} represents the local warehouse path

Pom Properties

${project.build.directory} represents the main source path

${project.build.sourceencoding} indicates the encoding format of the main source code

${project.build.sourcedirectory} represents the main source path

${project.build.finalname} indicates the output file name

${project.version} represents the project version, same as ${version}

Java System Properties

${user.home} indicates the user directory

${java.version} indicates the Java version

Environment variable Properties

${env. Java_home} represents the value of the JAVA_HOME environment variable

${env. HOME} indicates the user directory

Higher engineering variables

The variables in the pom of the superior project are referenced with the prefix ${project.parent}. The version of the superior project can also be referred to as: ${parent.version}

Maven's (eight) convention is better than configuration

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.