Skip to content

Building

Srikanta edited this page Jun 15, 2020 · 25 revisions

This document currently details Maven commands for building Azure SDK For Java.

JDK 8 vs JDK 11

The build system is configured to support JDK, as well as the current long-term support version of the JDK (currently JDK 11). The commands presented below will work on both JDKs.

Installing the build tools

A lot of the commands that follow will depend on the availability of the build tooling. This can be installed by running the following:

mvn install -f eng/code-quality-reports/pom.xml 

Building and Testing

To build all the libraries, run the following command

mvn install -f pom.xml -Dgpg.skip -Drevapi.skip -DskipTests

To build the new wave of track 2 libraries only, run the following command

mvn install -f pom.xml -Dgpg.skip -Drevapi.skip -DskipTests -pl com.azure:jacoco-test-coverage -am

To build the libraries for a specific service, run the following command

mvn install -f sdk/<servicename>/pom.xml  -Dgpg.skip -Drevapi.skip -DskipTests

For example, to build appconfiguration client library run the following command

mvn install -f sdk/appconfiguration/pom.xml -Dgpg.skip -Drevapi.skip -DskipTests

Testing for SpotBugs and CheckStyle issues

SpotBugs and CheckStyle are configured to break the build if there are any issues discovered by them. It is therefore strongly recommended to run the following maven goals locally before submitting a pull request:

mvn spotbugs:check checkstyle:checkstyle-aggregate -DskipTests -Dgpg.skip -pl "package-id:artifact-id" -am

Testing for breaking API changes

The build is configured with Revapi to check builds against the latest GA release in Maven. At present, the build is not configured to fail, but very soon it will be configured to fail the build when a breaking change is detected. To check for breaking changes, run the following:

mvn revapi:check

Skipping analysis for local build

The default mvn build/install command executes the code quality tools that run analysis for check-style violations, bugs and breaking changes. The build takes more time to complete with these analyses enabled. For intermediate build/install during local development, they can be skipped by adding the following mvn options:

-Dmaven.javadoc.skip=true -Dcheckstyle.skip=true -Dspotbugs.skip=true -Drevapi.skip=true

Note: It is strongly recommended to run the analysis locally before submitting a pull request.

Generating HTML reports

To generate HTML reports for 'Maven Site', as well as aggregate CheckStyle, SpotBugs, Jacoco, Revapi, and JavaDoc reports, you need to run the following commands:

Spotbugs, checkstyles, Revapi, and Javadocs
mvn install site:site site:stage -Dgpg.skip 
JaCoCo test coverage
mvn test -Dgpg.skip -Dinclude-non-shipping-modules

Once this completes, the generated reports are available in the following locations:

Tool Output Location
SpotBugs /eng/spotbugs-aggregate-report/target/spotbugs/spotbugsXml.html
CheckStyle /target/staging/checkstyle-aggregate.html
JavaDoc /target/staging/apidocs/index.html
Revapi /target/staging/revapi-aggregate-report.html
Maven Site /target/staging/index.html
JaCoCo /eng/jacoco-test-coverage/target/site/test-coverage/index.html

Code snippets in README

Samples in all README.md files should use compilable code to ensure they are updated when source code is updated. To do so, we use a utility tool to embed source code from Java files into README markdown files. Steps to add code snippets in README using the tool:

  • Download and install NodeJS
  • Create ReadmeSamples.java file in src/samples/java/ for which README.md should be updated
  • Add all the code snippets in the above Java file that should be included in README.md
  • Now, in README.md, add the embedme tag as shown below (the sample shows inserting code from line number 10 to 20)
<!-- embedme path/to/ReadmeSamples.java#L10-L20 -->
```java
```
  • To embed code using the tool, run the following command
npx embedme path/to/README.md
  • Verify the README.md file to confirm the samples are inserted as expected
Clone this wiki locally