330 lines
18 KiB
XML
330 lines
18 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
||
<?asciidoc-toc?>
|
||
<?asciidoc-numbered?>
|
||
<book xmlns="http://docbook.org/ns/docbook" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0" xml:lang="en">
|
||
<info>
|
||
<title>Spring Cloud Build</title>
|
||
<date>2020-01-31</date>
|
||
</info>
|
||
<preface>
|
||
<title></title>
|
||
<simpara><inlinemediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="https://circleci.com/gh/spring-cloud/spring-cloud-build.svg?style=svg"/>
|
||
</imageobject>
|
||
<textobject><phrase>spring cloud build</phrase></textobject>
|
||
</inlinemediaobject></simpara>
|
||
<simpara>Spring Cloud Build is a common utility project for Spring Cloud
|
||
to use for plugin and dependency management.</simpara>
|
||
</preface>
|
||
<chapter xml:id="_building_and_deploying">
|
||
<title>Building and Deploying</title>
|
||
<simpara>To install locally:</simpara>
|
||
<screen>$ mvn install -s .settings.xml</screen>
|
||
<simpara>and to deploy snapshots to repo.spring.io:</simpara>
|
||
<screen>$ mvn deploy -DaltSnapshotDeploymentRepository=repo.spring.io::default::https://repo.spring.io/libs-snapshot-local</screen>
|
||
<simpara>for a RELEASE build use</simpara>
|
||
<screen>$ mvn deploy -DaltReleaseDeploymentRepository=repo.spring.io::default::https://repo.spring.io/libs-release-local</screen>
|
||
<simpara>and for jcenter use</simpara>
|
||
<screen>$ mvn deploy -DaltReleaseDeploymentRepository=bintray::default::https://api.bintray.com/maven/spring/jars/org.springframework.cloud:build</screen>
|
||
<simpara>and for Maven Central use</simpara>
|
||
<screen>$ mvn deploy -P central -DaltReleaseDeploymentRepository=sonatype-nexus-staging::default::https://oss.sonatype.org/service/local/staging/deploy/maven2</screen>
|
||
<simpara>(the "central" profile is available for all projects in Spring Cloud and it sets up the gpg jar signing, and the repository has to be specified separately for this project because it is a parent of the starter parent which users in turn have as their own parent).</simpara>
|
||
</chapter>
|
||
<chapter xml:id="_contributing">
|
||
<title>Contributing</title>
|
||
<simpara>Spring Cloud is released under the non-restrictive Apache 2.0 license,
|
||
and follows a very standard Github development process, using Github
|
||
tracker for issues and merging pull requests into master. If you want
|
||
to contribute even something trivial please do not hesitate, but
|
||
follow the guidelines below.</simpara>
|
||
<section xml:id="_sign_the_contributor_license_agreement">
|
||
<title>Sign the Contributor License Agreement</title>
|
||
<simpara>Before we accept a non-trivial patch or pull request we will need you to sign the
|
||
<link xl:href="https://cla.pivotal.io/sign/spring">Contributor License Agreement</link>.
|
||
Signing the contributor’s agreement does not grant anyone commit rights to the main
|
||
repository, but it does mean that we can accept your contributions, and you will get an
|
||
author credit if we do. Active contributors might be asked to join the core team, and
|
||
given the ability to merge pull requests.</simpara>
|
||
</section>
|
||
<section xml:id="_code_of_conduct">
|
||
<title>Code of Conduct</title>
|
||
<simpara>This project adheres to the Contributor Covenant <link xl:href="https://github.com/spring-cloud/spring-cloud-build/blob/master/docs/src/main/asciidoc/code-of-conduct.adoc">code of
|
||
conduct</link>. By participating, you are expected to uphold this code. Please report
|
||
unacceptable behavior to <link xl:href="mailto:spring-code-of-conduct@pivotal.io">spring-code-of-conduct@pivotal.io</link>.</simpara>
|
||
</section>
|
||
<section xml:id="_code_conventions_and_housekeeping">
|
||
<title>Code Conventions and Housekeeping</title>
|
||
<simpara>None of these is essential for a pull request, but they will all help. They can also be
|
||
added after the original pull request but before a merge.</simpara>
|
||
<itemizedlist>
|
||
<listitem>
|
||
<simpara>Use the Spring Framework code format conventions. If you use Eclipse
|
||
you can import formatter settings using the
|
||
<literal>eclipse-code-formatter.xml</literal> file from the
|
||
<link xl:href="https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-dependencies-parent/eclipse-code-formatter.xml">Spring
|
||
Cloud Build</link> project. If using IntelliJ, you can use the
|
||
<link xl:href="https://plugins.jetbrains.com/plugin/6546">Eclipse Code Formatter
|
||
Plugin</link> to import the same file.</simpara>
|
||
</listitem>
|
||
<listitem>
|
||
<simpara>Make sure all new <literal>.java</literal> files to have a simple Javadoc class comment with at least an
|
||
<literal>@author</literal> tag identifying you, and preferably at least a paragraph on what the class is
|
||
for.</simpara>
|
||
</listitem>
|
||
<listitem>
|
||
<simpara>Add the ASF license header comment to all new <literal>.java</literal> files (copy from existing files
|
||
in the project)</simpara>
|
||
</listitem>
|
||
<listitem>
|
||
<simpara>Add yourself as an <literal>@author</literal> to the .java files that you modify substantially (more
|
||
than cosmetic changes).</simpara>
|
||
</listitem>
|
||
<listitem>
|
||
<simpara>Add some Javadocs and, if you change the namespace, some XSD doc elements.</simpara>
|
||
</listitem>
|
||
<listitem>
|
||
<simpara>A few unit tests would help a lot as well — someone has to do it.</simpara>
|
||
</listitem>
|
||
<listitem>
|
||
<simpara>If no-one else is using your branch, please rebase it against the current master (or
|
||
other target branch in the main project).</simpara>
|
||
</listitem>
|
||
<listitem>
|
||
<simpara>When writing a commit message please follow <link xl:href="https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html">these conventions</link>,
|
||
if you are fixing an existing issue please add <literal>Fixes gh-XXXX</literal> at the end of the commit
|
||
message (where XXXX is the issue number).</simpara>
|
||
</listitem>
|
||
</itemizedlist>
|
||
</section>
|
||
<section xml:id="_checkstyle">
|
||
<title>Checkstyle</title>
|
||
<simpara>Spring Cloud Build comes with a set of checkstyle rules. You can find them in the <literal>spring-cloud-build-tools</literal> module. The most notable files under the module are:</simpara>
|
||
<formalpara>
|
||
<title>spring-cloud-build-tools/</title>
|
||
<para>
|
||
<screen>└── src
|
||
├── checkstyle
|
||
│ └── checkstyle-suppressions.xml <co xml:id="CO1-1"/>
|
||
└── main
|
||
└── resources
|
||
├── checkstyle-header.txt <co xml:id="CO1-2"/>
|
||
└── checkstyle.xml <co xml:id="CO1-3"/></screen>
|
||
</para>
|
||
</formalpara>
|
||
<calloutlist>
|
||
<callout arearefs="CO1-3">
|
||
<para>Default Checkstyle rules</para>
|
||
</callout>
|
||
<callout arearefs="CO1-2">
|
||
<para>File header setup</para>
|
||
</callout>
|
||
<callout arearefs="CO1-1">
|
||
<para>Default suppression rules</para>
|
||
</callout>
|
||
</calloutlist>
|
||
<section xml:id="_checkstyle_configuration">
|
||
<title>Checkstyle configuration</title>
|
||
<simpara>Checkstyle rules are <emphasis role="strong">disabled by default</emphasis>. To add checkstyle to your project just define the following properties and plugins.</simpara>
|
||
<formalpara>
|
||
<title>pom.xml</title>
|
||
<para>
|
||
<screen><properties>
|
||
<maven-checkstyle-plugin.failsOnError>true</maven-checkstyle-plugin.failsOnError> <co xml:id="CO2-1"/>
|
||
<maven-checkstyle-plugin.failsOnViolation>true
|
||
</maven-checkstyle-plugin.failsOnViolation> <co xml:id="CO2-2"/>
|
||
<maven-checkstyle-plugin.includeTestSourceDirectory>true
|
||
</maven-checkstyle-plugin.includeTestSourceDirectory> <co xml:id="CO2-3"/>
|
||
</properties>
|
||
|
||
<build>
|
||
<plugins>
|
||
<plugin> <co xml:id="CO2-4"/>
|
||
<groupId>io.spring.javaformat</groupId>
|
||
<artifactId>spring-javaformat-maven-plugin</artifactId>
|
||
</plugin>
|
||
<plugin> <co xml:id="CO2-5"/>
|
||
<groupId>org.apache.maven.plugins</groupId>
|
||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||
</plugin>
|
||
</plugins>
|
||
|
||
<reporting>
|
||
<plugins>
|
||
<plugin> <co xml:id="CO2-6"/>
|
||
<groupId>org.apache.maven.plugins</groupId>
|
||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||
</plugin>
|
||
</plugins>
|
||
</reporting>
|
||
</build></screen>
|
||
</para>
|
||
</formalpara>
|
||
<calloutlist>
|
||
<callout arearefs="CO2-1">
|
||
<para>Fails the build upon Checkstyle errors</para>
|
||
</callout>
|
||
<callout arearefs="CO2-2">
|
||
<para>Fails the build upon Checkstyle violations</para>
|
||
</callout>
|
||
<callout arearefs="CO2-3">
|
||
<para>Checkstyle analyzes also the test sources</para>
|
||
</callout>
|
||
<callout arearefs="CO2-4">
|
||
<para>Add the Spring Java Format plugin that will reformat your code to pass most of the Checkstyle formatting rules</para>
|
||
</callout>
|
||
<callout arearefs="CO2-5 CO2-6">
|
||
<para>Add checkstyle plugin to your build and reporting phases</para>
|
||
</callout>
|
||
</calloutlist>
|
||
<simpara>If you need to suppress some rules (e.g. line length needs to be longer), then it’s enough for you to define a file under <literal>${project.root}/src/checkstyle/checkstyle-suppressions.xml</literal> with your suppressions. Example:</simpara>
|
||
<formalpara>
|
||
<title>projectRoot/src/checkstyle/checkstyle-suppresions.xml</title>
|
||
<para>
|
||
<screen><?xml version="1.0"?>
|
||
<!DOCTYPE suppressions PUBLIC
|
||
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
|
||
"https://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
|
||
<suppressions>
|
||
<suppress files=".*ConfigServerApplication\.java" checks="HideUtilityClassConstructor"/>
|
||
<suppress files=".*ConfigClientWatch\.java" checks="LineLengthCheck"/>
|
||
</suppressions></screen>
|
||
</para>
|
||
</formalpara>
|
||
<simpara>It’s advisable to copy the <literal>${spring-cloud-build.rootFolder}/.editorconfig</literal> and <literal>${spring-cloud-build.rootFolder}/.springformat</literal> to your project. That way, some default formatting rules will be applied. You can do so by running this script:</simpara>
|
||
<programlisting language="bash" linenumbering="unnumbered">$ curl https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/.editorconfig -o .editorconfig
|
||
$ touch .springformat</programlisting>
|
||
</section>
|
||
</section>
|
||
<section xml:id="_ide_setup">
|
||
<title>IDE setup</title>
|
||
<section xml:id="_intellij_idea">
|
||
<title>Intellij IDEA</title>
|
||
<simpara>In order to setup Intellij you should import our coding conventions, inspection profiles and set up the checkstyle plugin.
|
||
The following files can be found in the <link xl:href="https://github.com/spring-cloud/spring-cloud-build/tree/master/spring-cloud-build-tools">Spring Cloud Build</link> project.</simpara>
|
||
<formalpara>
|
||
<title>spring-cloud-build-tools/</title>
|
||
<para>
|
||
<screen>└── src
|
||
├── checkstyle
|
||
│ └── checkstyle-suppressions.xml <co xml:id="CO3-1"/>
|
||
└── main
|
||
└── resources
|
||
├── checkstyle-header.txt <co xml:id="CO3-2"/>
|
||
├── checkstyle.xml <co xml:id="CO3-3"/>
|
||
└── intellij
|
||
├── Intellij_Project_Defaults.xml <co xml:id="CO3-4"/>
|
||
└── Intellij_Spring_Boot_Java_Conventions.xml <co xml:id="CO3-5"/></screen>
|
||
</para>
|
||
</formalpara>
|
||
<calloutlist>
|
||
<callout arearefs="CO3-3">
|
||
<para>Default Checkstyle rules</para>
|
||
</callout>
|
||
<callout arearefs="CO3-2">
|
||
<para>File header setup</para>
|
||
</callout>
|
||
<callout arearefs="CO3-1">
|
||
<para>Default suppression rules</para>
|
||
</callout>
|
||
<callout arearefs="CO3-4">
|
||
<para>Project defaults for Intellij that apply most of Checkstyle rules</para>
|
||
</callout>
|
||
<callout arearefs="CO3-5">
|
||
<para>Project style conventions for Intellij that apply most of Checkstyle rules</para>
|
||
</callout>
|
||
</calloutlist>
|
||
<figure>
|
||
<title>Code style</title>
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/docs/src/main/asciidoc/images/intellij-code-style.png"/>
|
||
</imageobject>
|
||
<textobject><phrase>Code style</phrase></textobject>
|
||
</mediaobject>
|
||
</figure>
|
||
<simpara>Go to <literal>File</literal> → <literal>Settings</literal> → <literal>Editor</literal> → <literal>Code style</literal>. There click on the icon next to the <literal>Scheme</literal> section. There, click on the <literal>Import Scheme</literal> value and pick the <literal>Intellij IDEA code style XML</literal> option. Import the <literal>spring-cloud-build-tools/src/main/resources/intellij/Intellij_Spring_Boot_Java_Conventions.xml</literal> file.</simpara>
|
||
<figure>
|
||
<title>Inspection profiles</title>
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/docs/src/main/asciidoc/images/intellij-inspections.png"/>
|
||
</imageobject>
|
||
<textobject><phrase>Code style</phrase></textobject>
|
||
</mediaobject>
|
||
</figure>
|
||
<simpara>Go to <literal>File</literal> → <literal>Settings</literal> → <literal>Editor</literal> → <literal>Inspections</literal>. There click on the icon next to the <literal>Profile</literal> section. There, click on the <literal>Import Profile</literal> and import the <literal>spring-cloud-build-tools/src/main/resources/intellij/Intellij_Project_Defaults.xml</literal> file.</simpara>
|
||
<formalpara>
|
||
<title>Checkstyle</title>
|
||
<para>To have Intellij work with Checkstyle, you have to install the <literal>Checkstyle</literal> plugin. It’s advisable to also install the <literal>Assertions2Assertj</literal> to automatically convert the JUnit assertions</para>
|
||
</formalpara>
|
||
<informalfigure>
|
||
<mediaobject>
|
||
<imageobject>
|
||
<imagedata fileref="https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/docs/src/main/asciidoc/images/intellij-checkstyle.png"/>
|
||
</imageobject>
|
||
<textobject><phrase>Checkstyle</phrase></textobject>
|
||
</mediaobject>
|
||
</informalfigure>
|
||
<simpara>Go to <literal>File</literal> → <literal>Settings</literal> → <literal>Other settings</literal> → <literal>Checkstyle</literal>. There click on the <literal>+</literal> icon in the <literal>Configuration file</literal> section. There, you’ll have to define where the checkstyle rules should be picked from. In the image above, we’ve picked the rules from the cloned Spring Cloud Build repository. However, you can point to the Spring Cloud Build’s GitHub repository (e.g. for the <literal>checkstyle.xml</literal> : <literal><link xl:href="https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle.xml">https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle.xml</link></literal>). We need to provide the following variables:</simpara>
|
||
<itemizedlist>
|
||
<listitem>
|
||
<simpara><literal>checkstyle.header.file</literal> - please point it to the Spring Cloud Build’s, <literal>spring-cloud-build-tools/src/main/resources/checkstyle-header.txt</literal> file either in your cloned repo or via the <literal><link xl:href="https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle-header.txt">https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle-header.txt</link></literal> URL.</simpara>
|
||
</listitem>
|
||
<listitem>
|
||
<simpara><literal>checkstyle.suppressions.file</literal> - default suppressions. Please point it to the Spring Cloud Build’s, <literal>spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml</literal> file either in your cloned repo or via the <literal><link xl:href="https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml">https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml</link></literal> URL.</simpara>
|
||
</listitem>
|
||
<listitem>
|
||
<simpara><literal>checkstyle.additional.suppressions.file</literal> - this variable corresponds to suppressions in your local project. E.g. you’re working on <literal>spring-cloud-contract</literal>. Then point to the <literal>project-root/src/checkstyle/checkstyle-suppressions.xml</literal> folder. Example for <literal>spring-cloud-contract</literal> would be: <literal>/home/username/spring-cloud-contract/src/checkstyle/checkstyle-suppressions.xml</literal>.</simpara>
|
||
</listitem>
|
||
</itemizedlist>
|
||
<important>
|
||
<simpara>Remember to set the <literal>Scan Scope</literal> to <literal>All sources</literal> since we apply checkstyle rules for production and test sources.</simpara>
|
||
</important>
|
||
</section>
|
||
</section>
|
||
</chapter>
|
||
<chapter xml:id="_reusing_the_documentation">
|
||
<title>Reusing the documentation</title>
|
||
<simpara>Spring Cloud Build publishes its <literal>spring-cloud-build-docs</literal> module that contains
|
||
helpful scripts (e.g. README generation ruby script) and css, xslt and images
|
||
for the Spring Cloud documentation. If you want to follow the same convention
|
||
approach of generating documentation just add these plugins to your <literal>docs</literal> module</simpara>
|
||
<programlisting language="xml" linenumbering="unnumbered"><profiles>
|
||
<profile>
|
||
<id>docs</id>
|
||
<build>
|
||
<plugins>
|
||
<plugin>
|
||
<groupId>org.apache.maven.plugins</groupId>
|
||
<artifactId>maven-dependency-plugin</artifactId> <co xml:id="CO4-1"/>
|
||
</plugin>
|
||
<plugin>
|
||
<groupId>org.asciidoctor</groupId>
|
||
<artifactId>asciidoctor-maven-plugin</artifactId> <co xml:id="CO4-2"/>
|
||
</plugin>
|
||
<plugin>
|
||
<groupId>org.apache.maven.plugins</groupId>
|
||
<artifactId>maven-antrun-plugin</artifactId> <co xml:id="CO4-3"/>
|
||
<inherited>false</inherited>
|
||
</plugin>
|
||
</plugins>
|
||
</build>
|
||
</profile>
|
||
</profiles></programlisting>
|
||
<calloutlist>
|
||
<callout arearefs="CO4-1">
|
||
<para>This plugin downloads and unpacks the resources of the <literal>spring-cloud-build-docs</literal> module</para>
|
||
</callout>
|
||
<callout arearefs="CO4-2">
|
||
<para>This plugin is required to parse the Asciidoctor documentation</para>
|
||
</callout>
|
||
<callout arearefs="CO4-3">
|
||
<para>This plugin is required to copy resources into proper final destinations and to generate main README.adoc</para>
|
||
</callout>
|
||
</calloutlist>
|
||
<important>
|
||
<simpara>The order of plugin declaration is important!</simpara>
|
||
</important>
|
||
</chapter>
|
||
</book> |