Project

General

Profile

Developers' Best Practices » History » Version 19

Claudio Atzori, 20/11/2018 05:27 PM

1 1 Alessia Bardi
h1. Developers' Best Practices
2
3 3 Claudio Atzori
It is time for D-Net development teams to find a strategy to improve our developement work!
4 1 Alessia Bardi
5
The introduction of Jenkins and Nexus helped a lot in terms of code management, but now it is time to establish a set of guidelines to better co-ordinate our teams.
6
The following best practices are inspired by CNR developers' common sense, so we do not assume they are written in stones and applies as they are also in your cases.
7
8
So, you are strongly invited to comment/update this wiki page, so that we can reach a consensus. 
9 3 Claudio Atzori
10
h2. Coding
11
12 19 Claudio Atzori
Most of the D-Net modules have been migrated to from the old build system ant to maven. This implies some changes to the module directories and files. The starting point is the maven settings file describing the maven repository used when resolving module dependencies
13 1 Alessia Bardi
14 19 Claudio Atzori
<pre>
15
<?xml version="1.0" encoding="utf-8"?>
16
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
17
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
18
    xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
19
    http://maven.apache.org/xsd/settings-1.0.0.xsd">
20
    <servers>
21
        
22
        <server>
23
            <id>dnet45-releases</id>
24
            <username>{}</username>
25
            <password>{}</password>
26
        </server>
27
        <server>
28
            <id>dnet45-bootstrap-release</id>
29
            <username>{}</username>
30
            <password>{}</password>
31
        </server>
32
        
33
    </servers>
34
    
35
    <profiles>
36
        <profile>
37
            <id>dnet-bootstrap-profile</id>
38
            <activation>
39
                <activeByDefault>true</activeByDefault>
40
            </activation>
41
            <repositories>
42
                
43
                <repository>
44
                    <id>dnet45-bootstrap-snapshot</id>
45
                    <name>D-Net 45 Bootstrap Snapshot</name>
46
                    <url>http://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-bootstrap-snapshot/</url>
47
                    <releases>
48
                        <enabled>false</enabled>
49
                    </releases>
50
                    <snapshots>
51
                        <enabled>true</enabled>
52
                    </snapshots>
53
                    <layout>default</layout>
54
                </repository>
55
                
56
                <repository>
57
                    <id>dnet45-bootstrap-release</id>
58
                    <name>D-Net 45 Bootstrap Release</name>
59
                    <url>http://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-bootstrap-release/</url>
60
                    <releases>
61
                        <enabled>true</enabled>
62
                    </releases>
63
                    <snapshots>
64
                        <enabled>false</enabled>
65
                    </snapshots>
66
                    <layout>default</layout>
67
                </repository>
68
                
69
                <repository>
70
                    <id>dfm-releases</id>
71
                    <name>dfm-releases</name>
72
                    <url>http://maven.research-infrastructures.eu/nexus/content/repositories/dfm-releases/</url>
73
                    <releases>
74
                        <enabled>true</enabled>
75
                    </releases>
76
                    <snapshots>
77
                        <enabled>false</enabled>
78
                    </snapshots>
79
                    <layout>default</layout>
80
                </repository>
81
                
82
            </repositories>
83
        </profile>
84
    </profiles>
85
    <pluginGroups>
86
        <pluginGroup>org.apache.tomcat.maven</pluginGroup>
87
    </pluginGroups>
88
</settings>
89
90
</pre>
91
92 3 Claudio Atzori
Maven compliant D-Net module structure:
93
94
<pre>
95
.
96
├── pom.xml
97
├── src
98
│   ├── main
99
│   │   ├── java
100
│   │   │   └── eu
101
│   │   │       └── dnetlib
102
│   │   └── resources
103
│   │       └── eu
104
│   │           └── dnetlib
105
│   └── test
106
│       ├── java
107
│       │   └── eu
108
│       │       └── dnetlib
109
│       └── resources
110
│           └── eu
111
│               └── dnetlib
112
└── target
113
    └── classes
114
</pre>
115
116
Hint: consider to define the svn:ignore property, set on the module root
117
118
<pre>
119
cd <MODULE_NAME>
120
svn pe svn:ignore .
121
122
.classpath
123
.project
124
.settings
125
target 
126 1 Alessia Bardi
</pre>
127
128
h2. Branching
129
130 16 Alessia Bardi
It is always recommended to create a new branch when performing heavy changes to a module, rather than directly into trunk.
131 1 Alessia Bardi
Since branching and merging is usually a lot of pain, we can use this section to keep track useful commands:
132 16 Alessia Bardi
133 1 Alessia Bardi
* To merge the branch into trunk, you can follow this step by step tutorial: http://www.sepcot.com/blog/2007/04/SVN-Merge-Branch-Trunk
134 16 Alessia Bardi
* If you want to merge changes committed in one or more specific revisions of your branch into trunk, you can use the command:
135
@cd trunk@
136 19 Claudio Atzori
@svn merge -c revNumber -c anotherRevNumber https://svn.driver.research-infrastructures.eu/driver/dnet45/modules/yourBranch@
137 14 Alessia Bardi
138 17 Alessia Bardi
h2. Revert to previous version
139
140
Because sometimes devs commit things that should not have been committed....
141
@svn merge -r HEAD:<goodRevision> <pathToFileTorevert>@
142
where @<goodRevision>@ is the revision number prior to the wrong commit of @<pathToFileTorevert>@
143
144 2 Claudio Atzori
h2. Use CI: trust Jenkins!
145 1 Alessia Bardi
146
The developer should clean the @.m2/repository/eu@ local repository from time to time to be sure that there are no modules installed locally. 
147
148
Modules should be downloaded from Nexus in order to properly resolve dependencies.
149
150 5 Alessia Bardi
h2. Maven dependencies
151
152
For information about version conflict resolution with Maven3:
153
* http://docs.codehaus.org/display/MAVEN/Versioning
154
* https://cwiki.apache.org/confluence/display/MAVEN/Maven+3.x+Compatibility+Notes
155
156
Generally speaking, we suggest to use the keyword @LATEST@ to refer to the last available artifact (snapshot or release) for a module.
157
Keep in mind that Maven3 considers:
158
@1.0-alpha-1 < 1.0-beta-1 < 1.0-SNAPSHOT < 1.0 < 1.1-SNAPSHOT@
159
160 6 Alessia Bardi
h3. How to change the version number of a snapshot?
161 1 Alessia Bardi
162
Depending on the kind of changes you can decide to increase the artifact version according to the following guidelines:
163
* BIG CHANGES impact the MAJOR version number. Ex. @0.0.1 --> 1.0.0@
164
** Examples of big changes are: updates to service interfaces, shared libraries, new functionalities.
165
* MINOR CHANGES impact the MINOR version number. Ex. @1.2.5 --> 1.3.0@
166
** Examples of minor changes are: service internals, non-shared code and libraries, important bug fixes.
167
* BUG FIXES impact the BUILD version number. Ex. @1.4.2 --> 1.4.3@
168
** Examples are small bug fixes that do not affect other components 
169
170 6 Alessia Bardi
h2. Release Best Practices
171
172
h3. When/Why releasing a module?
173
174
* Generally speaking a developer should release a module when the code is mature enough to be used by others. 
175
* An early release should be available in case others are relying on a module that is currently under heavy development (i.e., frequent commits that imply frequent snapshot updates), in order to avoid blocking other development activities.
176 7 Alessia Bardi
* Before updating an interface (e.g., service interfaces) or library (e.g., common and utilities modules) a developer MUST ENSURE there is a release of the current version.
177 6 Alessia Bardi
178 1 Alessia Bardi
h3. How to release?
179
180 13 Alessia Bardi
Note that the maven release plugin works fine with *Apache Maven 3.0.5* and that is the version that we suggest you to use.
181
To know which maven version you are using run: <pre>mvn -version</pre>
182
If you have a newer version (e.g. 3.2.3), then you'll get the error @Return code is: 400, ReasonPhrase: Bad Request@ when running @mvn release:perform@.
183
However +the jar should have been correctly deployed+: we strongly suggest you to check this is true by logging into our "Nexus":http://maven.research-infrastructures.eu/nexus.
184
185 1 Alessia Bardi
These are the steps for the release of a module, given that developer has a fresh checkout of the module to be released.
186 13 Alessia Bardi
187 11 Alessia Bardi
# Add the following at the beginning of your @~/.m2/settings.xml@:
188 8 Alessia Bardi
<pre>
189
<servers>
190
 <server>
191 18 Claudio Atzori
      <id>dnet45-releases</id>
192 8 Alessia Bardi
      <username>your LDAP username</username>
193
      <password>your LDAP password</password>
194
   </server>
195
</servers>
196
</pre>
197 7 Alessia Bardi
# Add the SCM info (change @{project.name}@ with the actual name of the project):
198 6 Alessia Bardi
<pre>
199
<scm>
200 18 Claudio Atzori
   <developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet45/modules/{project.name}/trunk</developerConnection>
201 6 Alessia Bardi
</scm>
202
</pre>
203
# Set the parent to a released parent. Example:
204
<pre>
205
<parent>
206
   <groupId>eu.dnetlib</groupId>
207
   <artifactId>dnet-parent</artifactId>
208
   <version>1.0.0</version>
209
</parent>
210
</pre>
211 18 Claudio Atzori
# Ensure there are no snapshots included as dependencies. Snapshot dependencies won't be resolved anymore by maven because released parents have visibility only on the released repository (@dnet45-releases@). For example, if your module currently depends on 
212 6 Alessia Bardi
<pre>
213
<dependency>
214
	<groupId>eu.dnetlib</groupId>
215
	<artifactId>cnr-misc-utils</artifactId>
216
	<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
217
</dependency>
218
</pre>
219
You should change the dependency as follows:
220
<pre>
221
<dependency>
222
	<groupId>eu.dnetlib</groupId>
223
	<artifactId>cnr-misc-utils</artifactId>
224
	<version>[1.0.0,2.0.0)</version>
225
</dependency>
226
</pre>
227
Note that this implies that the dependency module (e.g. @cnr-misc-utils@) must have been released.
228 15 Alessia Bardi
# Commit the changes you made in the pom.xml 
229 6 Alessia Bardi
# Run @mvn release:prepare@ and answer the questions. Default answers are usually fine. This will:
230
#* copy your trunk into another svn folder (@tags@) 
231
#* update the versions in trunk and tags
232 18 Claudio Atzori
# Run @mvn release:perform@. This will deploy the artifact on Nexus in the release repository @dnet45-releases@.
233 8 Alessia Bardi
234 12 Alessia Bardi
If you experience any issue, open a ticket to CNR.