Code style and code specifications-maven

Source: Internet
Author: User

// Excerpted from: maven official website (http://maven.apache.org/developers/conventions/code.html) 2014-03-01 10: 43: 32 Java Code Style

The Maven style for Java is mainly:

  • White space: One space after control statements and between arguments (I. e.If (foo)InsteadIf (foo)),MyFunc (foo, bar, baz)InsteadMyFunc (foo, bar, baz)). No spaces after methods names (I. e.Void myMethod (), myMethod ("foo "))
  • Indentation: Always use 4 space indents andNeverUse tabs!
  • Blocks: Always enclose with a new line brace.
  • Line wrapping: Always use a 120-column line width for Java code and Javadoc.

Readingness: Specify code grouping members, if needed. For instance in a Mojo class, you cocould have:

public class MyMojo{    // ----------------------------------------------------------------------    // Mojo components    // ----------------------------------------------------------------------    /**     * Artifact factory.     *     * @component     */    private ArtifactFactory artifactFactory;    ...    // ----------------------------------------------------------------------    // Mojo parameters    // ----------------------------------------------------------------------    /**     * The POM.     *     * @parameter expression="${project}"     * @required     */    private MavenProject project;    ...    // ----------------------------------------------------------------------    // Mojo options    // ----------------------------------------------------------------------    ...    // ----------------------------------------------------------------------    // Public methods    // ----------------------------------------------------------------------    /**     * {@inheritDoc}     */    public void execute()        throws MojoExecutionException    {      ...    }    // ----------------------------------------------------------------------    // Protected methods    // ----------------------------------------------------------------------    ...    // ----------------------------------------------------------------------    // Private methods    // ----------------------------------------------------------------------    ...    // ----------------------------------------------------------------------    // Static methods    // ----------------------------------------------------------------------    ...}


XML Code Style

The Maven style for XML files is mainly:

  • Indentation: Always use 2 space indents, unless you're wrapping a new XML tags line in which case you shoshould indent 4 spaces.

Line Breaks: Always use a new line with indentation for complex XML types and no line break for simple XML types. Always use a new line to separate XML sections or blocks, for instance:

<aTag>  <simpleType>This is a simple type</simpleType>  <complexType>    <simpleType>This is a complex type</simpleType>  </complexType></aTag>

In some cases, adding comments cocould improve the readability of blocks, for instance:

    <!-- Simple XML documentation                                               -->

Or

    <!-- ====================================================================== -->    <!-- Block documentation                                                    -->    <!-- ====================================================================== -->



POM Code Convention

The team has voted during the end of June 2008 to follow a specific POM convention to ordering POM elements. The consequence of this vote is that the Maven project descriptor isNo moreConsidered as the reference for the ordering.

The following is the recommended ordering for all Maven POM files:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  <modelVersion/>  <parent/>  <groupId/>  <artifactId/>  <version/>  <packaging/>  <name/>  <description/>  <url/>  <inceptionYear/>  <organization/>  <licenses/>  <developers/>  <contributors/>  <mailingLists/>  <prerequisites/>  <modules/>  <scm/>  <issueManagement/>  <ciManagement/>  <distributionManagement/>  <properties/>  <dependencyManagement/>  <dependencies/>  <repositories/>  <pluginRepositories/>  <build/>  <reporting/>  <profiles/></project>

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.