670 lines
29 KiB
HTML
670 lines
29 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]-->
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<meta name="generator" content="Asciidoctor 1.5.8">
|
||
<title>Spring Cloud Schema Registry</title>
|
||
<link rel="stylesheet" href="css/spring.css">
|
||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
|
||
|
||
<style>
|
||
.hidden {
|
||
display: none;
|
||
}
|
||
|
||
.switch {
|
||
border-width: 1px 1px 0 1px;
|
||
border-style: solid;
|
||
border-color: #7a2518;
|
||
display: inline-block;
|
||
}
|
||
|
||
.switch--item {
|
||
padding: 10px;
|
||
background-color: #ffffff;
|
||
color: #7a2518;
|
||
display: inline-block;
|
||
cursor: pointer;
|
||
}
|
||
|
||
.switch--item:not(:first-child) {
|
||
border-width: 0 0 0 1px;
|
||
border-style: solid;
|
||
border-color: #7a2518;
|
||
}
|
||
|
||
.switch--item.selected {
|
||
background-color: #7a2519;
|
||
color: #ffffff;
|
||
}
|
||
</style>
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/zepto/1.2.0/zepto.min.js"></script>
|
||
<script type="text/javascript">
|
||
function addBlockSwitches() {
|
||
$('.primary').each(function() {
|
||
primary = $(this);
|
||
createSwitchItem(primary, createBlockSwitch(primary)).item.addClass("selected");
|
||
primary.children('.title').remove();
|
||
});
|
||
$('.secondary').each(function(idx, node) {
|
||
secondary = $(node);
|
||
primary = findPrimary(secondary);
|
||
switchItem = createSwitchItem(secondary, primary.children('.switch'));
|
||
switchItem.content.addClass('hidden');
|
||
findPrimary(secondary).append(switchItem.content);
|
||
secondary.remove();
|
||
});
|
||
}
|
||
|
||
function createBlockSwitch(primary) {
|
||
blockSwitch = $('<div class="switch"></div>');
|
||
primary.prepend(blockSwitch);
|
||
return blockSwitch;
|
||
}
|
||
|
||
function findPrimary(secondary) {
|
||
candidate = secondary.prev();
|
||
while (!candidate.is('.primary')) {
|
||
candidate = candidate.prev();
|
||
}
|
||
return candidate;
|
||
}
|
||
|
||
function createSwitchItem(block, blockSwitch) {
|
||
blockName = block.children('.title').text();
|
||
content = block.children('.content').first().append(block.next('.colist'));
|
||
item = $('<div class="switch--item">' + blockName + '</div>');
|
||
item.on('click', '', content, function(e) {
|
||
$(this).addClass('selected');
|
||
$(this).siblings().removeClass('selected');
|
||
e.data.siblings('.content').addClass('hidden');
|
||
e.data.removeClass('hidden');
|
||
});
|
||
blockSwitch.append(item);
|
||
return {'item': item, 'content': content};
|
||
}
|
||
|
||
function globalSwitch() {
|
||
$('.switch--item').each(function() {
|
||
$(this).off('click');
|
||
$(this).on('click', function() {
|
||
selectedText = $(this).text()
|
||
selectedIndex = $(this).index()
|
||
$(".switch--item").filter(function() { return ($(this).text() === selectedText) }).each(function() {
|
||
$(this).addClass('selected');
|
||
$(this).siblings().removeClass('selected');
|
||
selectedContent = $(this).parent().siblings(".content").eq(selectedIndex)
|
||
selectedContent.removeClass('hidden');
|
||
selectedContent.siblings().addClass('hidden');
|
||
});
|
||
});
|
||
});
|
||
}
|
||
|
||
$(addBlockSwitches);
|
||
$(globalSwitch);
|
||
|
||
</script>
|
||
|
||
</head>
|
||
<body class="book toc2 toc-left">
|
||
<div id="header">
|
||
<div id="toc" class="toc2">
|
||
<div id="toctitle">Table of Contents</div>
|
||
<ul class="sectlevel1">
|
||
<li><a href="#_spring_cloud_schema_registry">Spring Cloud Schema Registry</a>
|
||
<ul class="sectlevel3">
|
||
<li><a href="#_spring_cloud_schema_registry_overview">Spring Cloud Schema Registry overview</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a href="#_project_page">Project page</a></li>
|
||
<li><a href="#_building">Building</a>
|
||
<ul class="sectlevel2">
|
||
<li><a href="#_basic_compile_and_test">Basic Compile and Test</a></li>
|
||
<li><a href="#_documentation">Documentation</a></li>
|
||
<li><a href="#_working_with_the_code">Working with the code</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a href="#_contributing">Contributing</a>
|
||
<ul class="sectlevel2">
|
||
<li><a href="#_sign_the_contributor_license_agreement">Sign the Contributor License Agreement</a></li>
|
||
<li><a href="#_code_of_conduct">Code of Conduct</a></li>
|
||
<li><a href="#_code_conventions_and_housekeeping">Code Conventions and Housekeeping</a></li>
|
||
<li><a href="#_checkstyle">Checkstyle</a></li>
|
||
<li><a href="#_ide_setup">IDE setup</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
<div id="content">
|
||
<div class="sect1">
|
||
<h2 id="_spring_cloud_schema_registry"><a class="link" href="#_spring_cloud_schema_registry">Spring Cloud Schema Registry</a></h2>
|
||
<div class="sectionbody">
|
||
<div class="paragraph">
|
||
<p>When organizations have a messaging based pub/sub architecture and multiple producer and consumer microservices communicate each other, it is often necessary for all those microservices to agree on a contract that is based on a schema.
|
||
When such a schema needs to evolve to accommodate new business requirements, the existing components are still required to continue to work.
|
||
This project provides support for a standalone schema registry server using which aforementioned schema can be registered and used by the applications.
|
||
It also contains support for avro based schema registry clients, which essentially provide message converters that communicates with the schema registry for reconciling schema during message conversion.
|
||
The schema evolution support provided by this project works both with the aforementioned standalone schema registry as well as the scheam registry provided by Confluent that specifically works with Apache Kafka.</p>
|
||
</div>
|
||
<div class="sect3">
|
||
<h4 id="_spring_cloud_schema_registry_overview"><a class="link" href="#_spring_cloud_schema_registry_overview">Spring Cloud Schema Registry overview</a></h4>
|
||
<div class="paragraph">
|
||
<p>Spring Cloud Schema Registry provides support for schema evolution so that the data can be evolved over time and still work with older or newer producers and consumers and vice versa. Most serialization models, especially the ones that aim for portability across different platforms and languages, rely on a schema that describes how the data is serialized in the binary payload. In order to serialize the data and then to interpret it, both the sending and receiving sides must have access to a schema that describes the binary format. In certain cases, the schema can be inferred from the payload type on serialization or from the target type on deserialization.
|
||
However, many applications benefit from having access to an explicit schema that describes the binary data format.
|
||
A schema registry lets you store schema information in a textual format (typically JSON) and makes that information accessible to various applications that need it to receive and send data in binary format.
|
||
A schema is referenceable as a tuple consisting of:</p>
|
||
</div>
|
||
<div class="ulist">
|
||
<ul>
|
||
<li>
|
||
<p>A subject that is the logical name of the schema</p>
|
||
</li>
|
||
<li>
|
||
<p>The schema version</p>
|
||
</li>
|
||
<li>
|
||
<p>The schema format, which describes the binary format of the data</p>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
<div class="paragraph">
|
||
<p>Spring Cloud Schema Registry provides the following compoents</p>
|
||
</div>
|
||
<div class="ulist">
|
||
<ul>
|
||
<li>
|
||
<p>Standalone Schema Registry Server</p>
|
||
<div class="literalblock">
|
||
<div class="content">
|
||
<pre>By default, it is using an H2 database, but server can be used with other databases by providing appropriate datasource configuration.</pre>
|
||
</div>
|
||
</div>
|
||
</li>
|
||
<li>
|
||
<p>Schema registry clients capable of message marshalling by communicating with a Schema Registry.</p>
|
||
<div class="literalblock">
|
||
<div class="content">
|
||
<pre>Currently, the client can communicate to the standalone schema registry or the Confluent Schema Registry.</pre>
|
||
</div>
|
||
</div>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="sect1">
|
||
<h2 id="_project_page"><a class="link" href="#_project_page">Project page</a></h2>
|
||
<div class="sectionbody">
|
||
<div class="paragraph">
|
||
<p>You can read more about Spring Cloud Schema Registry by going to <a href="https://spring.io/projects/spring-cloud-schema-registry">the project page</a></p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="sect1">
|
||
<h2 id="_building"><a class="link" href="#_building">Building</a></h2>
|
||
<div class="sectionbody">
|
||
<div class="sect2">
|
||
<h3 id="_basic_compile_and_test"><a class="link" href="#_basic_compile_and_test">Basic Compile and Test</a></h3>
|
||
<div class="paragraph">
|
||
<p>To build the source you will need to install JDK 1.7.</p>
|
||
</div>
|
||
<div class="paragraph">
|
||
<p>Spring Cloud uses Maven for most build-related activities, and you
|
||
should be able to get off the ground quite quickly by cloning the
|
||
project you are interested in and typing</p>
|
||
</div>
|
||
<div class="listingblock">
|
||
<div class="content">
|
||
<pre>$ ./mvnw install</pre>
|
||
</div>
|
||
</div>
|
||
<div class="admonitionblock note">
|
||
<table>
|
||
<tr>
|
||
<td class="icon">
|
||
<i class="fa icon-note" title="Note"></i>
|
||
</td>
|
||
<td class="content">
|
||
You can also install Maven (>=3.3.3) yourself and run the <code>mvn</code> command
|
||
in place of <code>./mvnw</code> in the examples below. If you do that you also
|
||
might need to add <code>-P spring</code> if your local Maven settings do not
|
||
contain repository declarations for spring pre-release artifacts.
|
||
</td>
|
||
</tr>
|
||
</table>
|
||
</div>
|
||
<div class="admonitionblock note">
|
||
<table>
|
||
<tr>
|
||
<td class="icon">
|
||
<i class="fa icon-note" title="Note"></i>
|
||
</td>
|
||
<td class="content">
|
||
Be aware that you might need to increase the amount of memory
|
||
available to Maven by setting a <code>MAVEN_OPTS</code> environment variable with
|
||
a value like <code>-Xmx512m -XX:MaxPermSize=128m</code>. We try to cover this in
|
||
the <code>.mvn</code> configuration, so if you find you have to do it to make a
|
||
build succeed, please raise a ticket to get the settings added to
|
||
source control.
|
||
</td>
|
||
</tr>
|
||
</table>
|
||
</div>
|
||
<div class="paragraph">
|
||
<p>For hints on how to build the project look in <code>.travis.yml</code> if there
|
||
is one. There should be a "script" and maybe "install" command. Also
|
||
look at the "services" section to see if any services need to be
|
||
running locally (e.g. mongo or rabbit). Ignore the git-related bits
|
||
that you might find in "before_install" since they’re related to setting git
|
||
credentials and you already have those.</p>
|
||
</div>
|
||
<div class="paragraph">
|
||
<p>The projects that require middleware generally include a
|
||
<code>docker-compose.yml</code>, so consider using
|
||
<a href="https://docs.docker.com/compose/">Docker Compose</a> to run the middeware servers
|
||
in Docker containers. See the README in the
|
||
<a href="https://github.com/spring-cloud-samples/scripts">scripts demo
|
||
repository</a> for specific instructions about the common cases of mongo,
|
||
rabbit and redis.</p>
|
||
</div>
|
||
<div class="admonitionblock note">
|
||
<table>
|
||
<tr>
|
||
<td class="icon">
|
||
<i class="fa icon-note" title="Note"></i>
|
||
</td>
|
||
<td class="content">
|
||
If all else fails, build with the command from <code>.travis.yml</code> (usually
|
||
<code>./mvnw install</code>).
|
||
</td>
|
||
</tr>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
<div class="sect2">
|
||
<h3 id="_documentation"><a class="link" href="#_documentation">Documentation</a></h3>
|
||
<div class="paragraph">
|
||
<p>The spring-cloud-build module has a "docs" profile, and if you switch
|
||
that on it will try to build asciidoc sources from
|
||
<code>src/main/asciidoc</code>. As part of that process it will look for a
|
||
<code>README.adoc</code> and process it by loading all the includes, but not
|
||
parsing or rendering it, just copying it to <code>${main.basedir}</code>
|
||
(defaults to <code>${basedir}</code>, i.e. the root of the project). If there are
|
||
any changes in the README it will then show up after a Maven build as
|
||
a modified file in the correct place. Just commit it and push the change.</p>
|
||
</div>
|
||
</div>
|
||
<div class="sect2">
|
||
<h3 id="_working_with_the_code"><a class="link" href="#_working_with_the_code">Working with the code</a></h3>
|
||
<div class="paragraph">
|
||
<p>If you don’t have an IDE preference we would recommend that you use
|
||
<a href="https://www.springsource.com/developer/sts">Spring Tools Suite</a> or
|
||
<a href="https://eclipse.org">Eclipse</a> when working with the code. We use the
|
||
<a href="https://eclipse.org/m2e/">m2eclipse</a> eclipse plugin for maven support. Other IDEs and tools
|
||
should also work without issue as long as they use Maven 3.3.3 or better.</p>
|
||
</div>
|
||
<div class="sect3">
|
||
<h4 id="_importing_into_eclipse_with_m2eclipse"><a class="link" href="#_importing_into_eclipse_with_m2eclipse">Importing into eclipse with m2eclipse</a></h4>
|
||
<div class="paragraph">
|
||
<p>We recommend the <a href="https://eclipse.org/m2e/">m2eclipse</a> eclipse plugin when working with
|
||
eclipse. If you don’t already have m2eclipse installed it is available from the "eclipse
|
||
marketplace".</p>
|
||
</div>
|
||
<div class="admonitionblock note">
|
||
<table>
|
||
<tr>
|
||
<td class="icon">
|
||
<i class="fa icon-note" title="Note"></i>
|
||
</td>
|
||
<td class="content">
|
||
Older versions of m2e do not support Maven 3.3, so once the
|
||
projects are imported into Eclipse you will also need to tell
|
||
m2eclipse to use the right profile for the projects. If you
|
||
see many different errors related to the POMs in the projects, check
|
||
that you have an up to date installation. If you can’t upgrade m2e,
|
||
add the "spring" profile to your <code>settings.xml</code>. Alternatively you can
|
||
copy the repository settings from the "spring" profile of the parent
|
||
pom into your <code>settings.xml</code>.
|
||
</td>
|
||
</tr>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
<div class="sect3">
|
||
<h4 id="_importing_into_eclipse_without_m2eclipse"><a class="link" href="#_importing_into_eclipse_without_m2eclipse">Importing into eclipse without m2eclipse</a></h4>
|
||
<div class="paragraph">
|
||
<p>If you prefer not to use m2eclipse you can generate eclipse project metadata using the
|
||
following command:</p>
|
||
</div>
|
||
<div class="listingblock">
|
||
<div class="content">
|
||
<pre>$ ./mvnw eclipse:eclipse</pre>
|
||
</div>
|
||
</div>
|
||
<div class="paragraph">
|
||
<p>The generated eclipse projects can be imported by selecting <code>import existing projects</code>
|
||
from the <code>file</code> menu.</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="sect1">
|
||
<h2 id="_contributing"><a class="link" href="#_contributing">Contributing</a></h2>
|
||
<div class="sectionbody">
|
||
<div class="paragraph">
|
||
<p>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.</p>
|
||
</div>
|
||
<div class="sect2">
|
||
<h3 id="_sign_the_contributor_license_agreement"><a class="link" href="#_sign_the_contributor_license_agreement">Sign the Contributor License Agreement</a></h3>
|
||
<div class="paragraph">
|
||
<p>Before we accept a non-trivial patch or pull request we will need you to sign the
|
||
<a href="https://cla.pivotal.io/sign/spring">Contributor License Agreement</a>.
|
||
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.</p>
|
||
</div>
|
||
</div>
|
||
<div class="sect2">
|
||
<h3 id="_code_of_conduct"><a class="link" href="#_code_of_conduct">Code of Conduct</a></h3>
|
||
<div class="paragraph">
|
||
<p>This project adheres to the Contributor Covenant <a href="https://github.com/spring-cloud/spring-cloud-build/blob/master/docs/src/main/asciidoc/code-of-conduct.adoc">code of
|
||
conduct</a>. By participating, you are expected to uphold this code. Please report
|
||
unacceptable behavior to <a href="mailto:spring-code-of-conduct@pivotal.io">spring-code-of-conduct@pivotal.io</a>.</p>
|
||
</div>
|
||
</div>
|
||
<div class="sect2">
|
||
<h3 id="_code_conventions_and_housekeeping"><a class="link" href="#_code_conventions_and_housekeeping">Code Conventions and Housekeeping</a></h3>
|
||
<div class="paragraph">
|
||
<p>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.</p>
|
||
</div>
|
||
<div class="ulist">
|
||
<ul>
|
||
<li>
|
||
<p>Use the Spring Framework code format conventions. If you use Eclipse
|
||
you can import formatter settings using the
|
||
<code>eclipse-code-formatter.xml</code> file from the
|
||
<a href="https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-dependencies-parent/eclipse-code-formatter.xml">Spring
|
||
Cloud Build</a> project. If using IntelliJ, you can use the
|
||
<a href="https://plugins.jetbrains.com/plugin/6546">Eclipse Code Formatter
|
||
Plugin</a> to import the same file.</p>
|
||
</li>
|
||
<li>
|
||
<p>Make sure all new <code>.java</code> files to have a simple Javadoc class comment with at least an
|
||
<code>@author</code> tag identifying you, and preferably at least a paragraph on what the class is
|
||
for.</p>
|
||
</li>
|
||
<li>
|
||
<p>Add the ASF license header comment to all new <code>.java</code> files (copy from existing files
|
||
in the project)</p>
|
||
</li>
|
||
<li>
|
||
<p>Add yourself as an <code>@author</code> to the .java files that you modify substantially (more
|
||
than cosmetic changes).</p>
|
||
</li>
|
||
<li>
|
||
<p>Add some Javadocs and, if you change the namespace, some XSD doc elements.</p>
|
||
</li>
|
||
<li>
|
||
<p>A few unit tests would help a lot as well — someone has to do it.</p>
|
||
</li>
|
||
<li>
|
||
<p>If no-one else is using your branch, please rebase it against the current master (or
|
||
other target branch in the main project).</p>
|
||
</li>
|
||
<li>
|
||
<p>When writing a commit message please follow <a href="https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html">these conventions</a>,
|
||
if you are fixing an existing issue please add <code>Fixes gh-XXXX</code> at the end of the commit
|
||
message (where XXXX is the issue number).</p>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
<div class="sect2">
|
||
<h3 id="_checkstyle"><a class="link" href="#_checkstyle">Checkstyle</a></h3>
|
||
<div class="paragraph">
|
||
<p>Spring Cloud Build comes with a set of checkstyle rules. You can find them in the <code>spring-cloud-build-tools</code> module. The most notable files under the module are:</p>
|
||
</div>
|
||
<div class="listingblock">
|
||
<div class="title">spring-cloud-build-tools/</div>
|
||
<div class="content">
|
||
<pre>└── src
|
||
├── checkstyle
|
||
│ └── checkstyle-suppressions.xml <i class="conum" data-value="3"></i><b>(3)</b>
|
||
└── main
|
||
└── resources
|
||
├── checkstyle-header.txt <i class="conum" data-value="2"></i><b>(2)</b>
|
||
└── checkstyle.xml <i class="conum" data-value="1"></i><b>(1)</b></pre>
|
||
</div>
|
||
</div>
|
||
<div class="colist arabic">
|
||
<table>
|
||
<tr>
|
||
<td><i class="conum" data-value="1"></i><b>1</b></td>
|
||
<td>Default Checkstyle rules</td>
|
||
</tr>
|
||
<tr>
|
||
<td><i class="conum" data-value="2"></i><b>2</b></td>
|
||
<td>File header setup</td>
|
||
</tr>
|
||
<tr>
|
||
<td><i class="conum" data-value="3"></i><b>3</b></td>
|
||
<td>Default suppression rules</td>
|
||
</tr>
|
||
</table>
|
||
</div>
|
||
<div class="sect3">
|
||
<h4 id="_checkstyle_configuration"><a class="link" href="#_checkstyle_configuration">Checkstyle configuration</a></h4>
|
||
<div class="paragraph">
|
||
<p>Checkstyle rules are <strong>disabled by default</strong>. To add checkstyle to your project just define the following properties and plugins.</p>
|
||
</div>
|
||
<div class="listingblock">
|
||
<div class="title">pom.xml</div>
|
||
<div class="content">
|
||
<pre><properties>
|
||
<maven-checkstyle-plugin.failsOnError>true</maven-checkstyle-plugin.failsOnError> <i class="conum" data-value="1"></i><b>(1)</b>
|
||
<maven-checkstyle-plugin.failsOnViolation>true
|
||
</maven-checkstyle-plugin.failsOnViolation> <i class="conum" data-value="2"></i><b>(2)</b>
|
||
<maven-checkstyle-plugin.includeTestSourceDirectory>true
|
||
</maven-checkstyle-plugin.includeTestSourceDirectory> <i class="conum" data-value="3"></i><b>(3)</b>
|
||
</properties>
|
||
|
||
<build>
|
||
<plugins>
|
||
<plugin> <i class="conum" data-value="4"></i><b>(4)</b>
|
||
<groupId>io.spring.javaformat</groupId>
|
||
<artifactId>spring-javaformat-maven-plugin</artifactId>
|
||
</plugin>
|
||
<plugin> <i class="conum" data-value="5"></i><b>(5)</b>
|
||
<groupId>org.apache.maven.plugins</groupId>
|
||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||
</plugin>
|
||
</plugins>
|
||
|
||
<reporting>
|
||
<plugins>
|
||
<plugin> <i class="conum" data-value="5"></i><b>(5)</b>
|
||
<groupId>org.apache.maven.plugins</groupId>
|
||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||
</plugin>
|
||
</plugins>
|
||
</reporting>
|
||
</build></pre>
|
||
</div>
|
||
</div>
|
||
<div class="colist arabic">
|
||
<table>
|
||
<tr>
|
||
<td><i class="conum" data-value="1"></i><b>1</b></td>
|
||
<td>Fails the build upon Checkstyle errors</td>
|
||
</tr>
|
||
<tr>
|
||
<td><i class="conum" data-value="2"></i><b>2</b></td>
|
||
<td>Fails the build upon Checkstyle violations</td>
|
||
</tr>
|
||
<tr>
|
||
<td><i class="conum" data-value="3"></i><b>3</b></td>
|
||
<td>Checkstyle analyzes also the test sources</td>
|
||
</tr>
|
||
<tr>
|
||
<td><i class="conum" data-value="4"></i><b>4</b></td>
|
||
<td>Add the Spring Java Format plugin that will reformat your code to pass most of the Checkstyle formatting rules</td>
|
||
</tr>
|
||
<tr>
|
||
<td><i class="conum" data-value="5"></i><b>5</b></td>
|
||
<td>Add checkstyle plugin to your build and reporting phases</td>
|
||
</tr>
|
||
</table>
|
||
</div>
|
||
<div class="paragraph">
|
||
<p>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 <code>${project.root}/src/checkstyle/checkstyle-suppressions.xml</code> with your suppressions. Example:</p>
|
||
</div>
|
||
<div class="listingblock">
|
||
<div class="title">projectRoot/src/checkstyle/checkstyle-suppresions.xml</div>
|
||
<div class="content">
|
||
<pre><?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></pre>
|
||
</div>
|
||
</div>
|
||
<div class="paragraph">
|
||
<p>It’s advisable to copy the <code>${spring-cloud-build.rootFolder}/.editorconfig</code> and <code>${spring-cloud-build.rootFolder}/.springformat</code> to your project. That way, some default formatting rules will be applied. You can do so by running this script:</p>
|
||
</div>
|
||
<div class="listingblock">
|
||
<div class="content">
|
||
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ curl https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/.editorconfig -o .editorconfig
|
||
$ touch .springformat</code></pre>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="sect2">
|
||
<h3 id="_ide_setup"><a class="link" href="#_ide_setup">IDE setup</a></h3>
|
||
<div class="sect3">
|
||
<h4 id="_intellij_idea"><a class="link" href="#_intellij_idea">Intellij IDEA</a></h4>
|
||
<div class="paragraph">
|
||
<p>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 <a href="https://github.com/spring-cloud/spring-cloud-build/tree/master/spring-cloud-build-tools">Spring Cloud Build</a> project.</p>
|
||
</div>
|
||
<div class="listingblock">
|
||
<div class="title">spring-cloud-build-tools/</div>
|
||
<div class="content">
|
||
<pre>└── src
|
||
├── checkstyle
|
||
│ └── checkstyle-suppressions.xml <i class="conum" data-value="3"></i><b>(3)</b>
|
||
└── main
|
||
└── resources
|
||
├── checkstyle-header.txt <i class="conum" data-value="2"></i><b>(2)</b>
|
||
├── checkstyle.xml <i class="conum" data-value="1"></i><b>(1)</b>
|
||
└── intellij
|
||
├── Intellij_Project_Defaults.xml <i class="conum" data-value="4"></i><b>(4)</b>
|
||
└── Intellij_Spring_Boot_Java_Conventions.xml <i class="conum" data-value="5"></i><b>(5)</b></pre>
|
||
</div>
|
||
</div>
|
||
<div class="colist arabic">
|
||
<table>
|
||
<tr>
|
||
<td><i class="conum" data-value="1"></i><b>1</b></td>
|
||
<td>Default Checkstyle rules</td>
|
||
</tr>
|
||
<tr>
|
||
<td><i class="conum" data-value="2"></i><b>2</b></td>
|
||
<td>File header setup</td>
|
||
</tr>
|
||
<tr>
|
||
<td><i class="conum" data-value="3"></i><b>3</b></td>
|
||
<td>Default suppression rules</td>
|
||
</tr>
|
||
<tr>
|
||
<td><i class="conum" data-value="4"></i><b>4</b></td>
|
||
<td>Project defaults for Intellij that apply most of Checkstyle rules</td>
|
||
</tr>
|
||
<tr>
|
||
<td><i class="conum" data-value="5"></i><b>5</b></td>
|
||
<td>Project style conventions for Intellij that apply most of Checkstyle rules</td>
|
||
</tr>
|
||
</table>
|
||
</div>
|
||
<div class="imageblock">
|
||
<div class="content">
|
||
<img src="https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/docs/src/main/asciidoc/images/intellij-code-style.png" alt="Code style">
|
||
</div>
|
||
<div class="title">Figure 1. Code style</div>
|
||
</div>
|
||
<div class="paragraph">
|
||
<p>Go to <code>File</code> → <code>Settings</code> → <code>Editor</code> → <code>Code style</code>. There click on the icon next to the <code>Scheme</code> section. There, click on the <code>Import Scheme</code> value and pick the <code>Intellij IDEA code style XML</code> option. Import the <code>spring-cloud-build-tools/src/main/resources/intellij/Intellij_Spring_Boot_Java_Conventions.xml</code> file.</p>
|
||
</div>
|
||
<div class="imageblock">
|
||
<div class="content">
|
||
<img src="https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/docs/src/main/asciidoc/images/intellij-inspections.png" alt="Code style">
|
||
</div>
|
||
<div class="title">Figure 2. Inspection profiles</div>
|
||
</div>
|
||
<div class="paragraph">
|
||
<p>Go to <code>File</code> → <code>Settings</code> → <code>Editor</code> → <code>Inspections</code>. There click on the icon next to the <code>Profile</code> section. There, click on the <code>Import Profile</code> and import the <code>spring-cloud-build-tools/src/main/resources/intellij/Intellij_Project_Defaults.xml</code> file.</p>
|
||
</div>
|
||
<div class="paragraph">
|
||
<div class="title">Checkstyle</div>
|
||
<p>To have Intellij work with Checkstyle, you have to install the <code>Checkstyle</code> plugin. It’s advisable to also install the <code>Assertions2Assertj</code> to automatically convert the JUnit assertions</p>
|
||
</div>
|
||
<div class="imageblock">
|
||
<div class="content">
|
||
<img src="https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/docs/src/main/asciidoc/images/intellij-checkstyle.png" alt="Checkstyle">
|
||
</div>
|
||
</div>
|
||
<div class="paragraph">
|
||
<p>Go to <code>File</code> → <code>Settings</code> → <code>Other settings</code> → <code>Checkstyle</code>. There click on the <code>+</code> icon in the <code>Configuration file</code> 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 <code>checkstyle.xml</code> : <code><a href="https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle.xml" class="bare">https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle.xml</a></code>). We need to provide the following variables:</p>
|
||
</div>
|
||
<div class="ulist">
|
||
<ul>
|
||
<li>
|
||
<p><code>checkstyle.header.file</code> - please point it to the Spring Cloud Build’s, <code>spring-cloud-build-tools/src/main/resources/checkstyle-header.txt</code> file either in your cloned repo or via the <code><a href="https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle-header.txt" class="bare">https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/main/resources/checkstyle-header.txt</a></code> URL.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>checkstyle.suppressions.file</code> - default suppressions. Please point it to the Spring Cloud Build’s, <code>spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml</code> file either in your cloned repo or via the <code><a href="https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml" class="bare">https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml</a></code> URL.</p>
|
||
</li>
|
||
<li>
|
||
<p><code>checkstyle.additional.suppressions.file</code> - this variable corresponds to suppressions in your local project. E.g. you’re working on <code>spring-cloud-contract</code>. Then point to the <code>project-root/src/checkstyle/checkstyle-suppressions.xml</code> folder. Example for <code>spring-cloud-contract</code> would be: <code>/home/username/spring-cloud-contract/src/checkstyle/checkstyle-suppressions.xml</code>.</p>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
<div class="admonitionblock important">
|
||
<table>
|
||
<tr>
|
||
<td class="icon">
|
||
<i class="fa icon-important" title="Important"></i>
|
||
</td>
|
||
<td class="content">
|
||
Remember to set the <code>Scan Scope</code> to <code>All sources</code> since we apply checkstyle rules for production and test sources.
|
||
</td>
|
||
</tr>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<script type="text/javascript" src="js/tocbot/tocbot.min.js"></script>
|
||
<script type="text/javascript" src="js/toc.js"></script>
|
||
<link rel="stylesheet" href="js/highlight/styles/github.min.css">
|
||
<script src="js/highlight/highlight.min.js"></script>
|
||
<script>hljs.initHighlighting()</script>
|
||
</body>
|
||
</html> |