Rechercher dans ce blog

lundi 23 avril 2012

3. Maven

"Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information."
http://maven.apache.org/

The purpose of maven in this project will be to create builds, unit tests and be able to manage through a few XML scripts. In this project, we will have three configuration file:

  • yocto-api: managing the different modules and the whole build
  • yocto-common: will provide all the objects to manage yoctopuce devices. It does not contain the communication piece (as we will create one module as standalone jar and the other as a GWT module).
  • yocto-standalone: will contain the communication layer in case we run in standard JRE.

Yocto-api

The first step is to create the root configuration. This configuration will contain the description of the project and the different modules and dependencies which are needed.
To create a project, the command mvn archetype:generate and we have to specify a few items: groupId,artifactId,version, etc. But for simplicity, I decided that Intellij Idea would create it for me. So I create a new project with Intellij Idea and selected that I wanted a Maven project. And that's all! My project was created,I started to make a first few changes and I obtained such pom.xml file:

1    <?xml version="1.0" encoding="UTF-8"?> 
2     
3    <project xmlns="http://maven.apache.org/POM/4.0.0" 
4             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
5             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
6             http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
7        <modelVersion>4.0.0</modelVersion> 
8     
9        <properties> 
10           <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
11       </properties> 
12    
13       <groupId>yocto-api</groupId> 
14       <artifactId>yocto-api</artifactId> 
15       <packaging>pom</packaging> 
16       <version>1.0</version> 
17       <modules> 
18           <module>yocto-standalone</module> 
19           <module>yocto-common</module> 
20       </modules> 
21    
22       <dependencies> 
23           <dependency> 
24               <groupId>junit</groupId> 
25               <artifactId>junit</artifactId> 
26               <version>4.8.2</version> 
27           </dependency> 
28           <dependency> 
29               <groupId>org.easymock</groupId> 
30               <artifactId>easymock</artifactId> 
31               <version>2.0</version> 
32           </dependency> 
33       </dependencies>
Let me describe a bit some items here:
  • The project has been called: yocto-api:yocto-api. The name is silly but I am not very imaginative. The version is 1.0.
  • The project has two modules: yocto-standalone and yocto-common. I will explain them later. But
  • I have added a few dependencies to the project: these are libraries that are used by the source code. Junit and easyMock are used for unit tests. This will be described in a future post. The good point is that only setting this is needed to use them. the Jars will be downloaded automatically by maven on http://repo.maven.apache.org/. You can get the list here as well: http://mvnrepository.com/
Now, let's describe one module: yocto-standalone. Yocto-common is straightforward...

Yocto-standalone

As explained before, yocto-standalone will only provide the communication layer to communicate with the yoctopuce devices.

1    <?xml version="1.0" encoding="UTF-8"?> 
2    <project xmlns="http://maven.apache.org/POM/4.0.0" 
3             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
4             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
5        <parent> 
6            <artifactId>yocto-api</artifactId> 
7            <groupId>yocto-api</groupId> 
8            <version>1.0</version> 
9        </parent> 
10       <modelVersion>4.0.0</modelVersion> 
11    
12       <artifactId>yocto-standalone</artifactId> 
13    
14       <dependencies> 
15           <dependency> 
16               <groupId>yocto-api</groupId> 
17               <artifactId>yocto-common</artifactId> 
18               <version>1.0</version> 
19           </dependency> 
20           <dependency> 
21               <groupId>org.codehaus.jackson</groupId> 
22               <artifactId>jackson-mapper-asl</artifactId> 
23               <version>1.8.5</version> 
24           </dependency> 
25    
26       </dependencies>

We can see that the code is very similar to the main pom.xml file except the dependencies because this module requires:
  • yocto-common as yocto-common contains all the classes needed for the standalone version
  • jackson to manage the json objects returned by the yoctopuce devices.
This is only what needed to be done. we can now run a few goals using the maven command: compile,clean,test,etc.

Aucun commentaire:

Enregistrer un commentaire