Build

About Codenvy Build

A build system provides a mechanism to compile files, create packages and artefacts, run unit tests, resolve dependencies, and gain access to external libraries. Codenvy’s core build system is based upon Maven. In the future, we will be opening up Codenvy to support other build systems. Codenvy is linked to Maven central to access centralized libraries, and also runs a local Nexus that stores libraries for use by our customers. With Maven you can create sophisticated compilation and packaging sequences, access external libraries, and load your own local libraries. This section teaches you what is needed to make use of Maven with your projects.

Getting Started With Maven

Maven is a popular build manager for Java projects similar to Apache Ant. Maven also supports Ruby, C#, Scala, and other languages, and uses pom.xml file to describe the project, the configuration of plugins, its dependencies on other external modules and libraries, the packaging (for example, war or jar for Java) etc. You can find a more detailed description of Maven’s pom.xml file at Maven website and general info at http://maven.apache.org/index.html.

maven

Check out Publishing JAR Projects and Managing Project Dependencies section of this manual to learn how to publish own Java Libraries and configure pom.xml files to use them in your projects.

Configuring Project Dependencies

You can use popular Java libraries in your projects, by adding relevant dependencies to a project’s pom.xml file, making necessary import statements and adding relevant strings to project’s class file. Below is an example of using a popular commons.lang library from Nexus Central.

  • a supported commons-lang library has been found on Nexus Central

nexus_central

  • open an existing Spring project or create a new one, and add a new dependency to its pom.xml file

pom_dependency

  • save the project and update dependency at Project > Update Dependency
  • open Java class file, GreetingController.java in our case and add a new import statement and string

classfile

(info) You can call code autocomplete feature and choose one of the many available string values, like user name or user time zone (user country has been chosen in the above screenshot)

autocomplete_code

  • Save the project and run the app from Run > Run Application menu
  • Enter name in the box and check out the results

app_online

The app returned info on the entered name and user country.

Surefire Reports

Codenvy users can access Maven’s surefire reports right from the Output Tab. If a build fails because of a failed test, you will find relevant information in the Output panel with the link to surefire reports.

surefire

Reports in txt and xml extensions are available.

surefire_reports
The txt report focuses on code lines that caused test failures.

-------------------------------------------------------------------------------
Test set: hello.SayHelloTest
-------------------------------------------------------------------------------
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.022 sec - FAILURE!
testSayHello(hello.SayHelloTest)  Time elapsed: 0.008 sec - FAILURE!
junit.framework.AssertionFailedError
	at junit.framework.Assert.fail(Assert.java:47)
	at junit.framework.Assert.assertTrue(Assert.java:20)
	at junit.framework.Assert.assertTrue(Assert.java:27)
	at hello.SayHelloTest.testSayHello(SayHelloTest.java:36)

Here’s a short video with an example of a failed build and a closer look at surefire reports

Add a Local Library

If you need to use a library that is not in Maven’s central repository, it is possible to manually add a local JAR file to your project:

  • add the following to your project’s pom.xml file
  <repositories>
   <repository>
    <id>repo</id>
    <url>file://${project.basedir}/repo</url>
  </repository>
  </repositories>
  • add a dependency for your library to pom.xml file, something like
    <dependency>
      <groupId>info.aduna.commons</groupId>
      <artifactId>aduna-commons-text</artifactId>
      <version>2.7.0</version>
    </dependency>
  • create folder in project root – /repo/info/aduna/commons/aduna-commons-text/2.7.0/ which is a standard structure of maven repository where folders under the repo folder are named as group ID elements, artifact ID and version respectively, and upload your local jar there

Up ↑