Revision 40513 trunk/org.gvsig.desktop/maven-howto.rst

View differences:

maven-howto.rst
1 1

  
2
- How to reduce the process of "install" to run as fast as possible.
2
==================================
3
Usefull maven "howtos" and FAQs
4
==================================
3 5

  
4
  Can reduce install execution skiping test execution and compilation,
5
  javadoc generation, test signature checking, license checking, and 
6
  attach sources in jar.
6
.. contents::
7 7

  
8
    mvn -Dsource.skip=true -Dmaven.test.skip=true -DskipTests -Dmaven.javadoc.skip=true -Danimal.sniffer.skip=true -Dlicense.skip=true install
8
How to reduce the process of "install" to run as fast as possible.
9
-------------------------------------------------------------------
9 10

  
10
- How show the list of files that have problems with the header.
11
Can reduce install execution skiping test execution and compilation,
12
javadoc generation, test signature checking, license checking, and 
13
attach sources in jar.
11 14

  
15
  mvn -Dsource.skip=true -Dmaven.test.skip=true -DskipTests -Dmaven.javadoc.skip=true -Danimal.sniffer.skip=true -Dlicense.skip=true install
16

  
17
How show the list of files that have problems with the header.
18
----------------------------------------------------------------
19

  
20
You can use the mave plugin "license" to check the headers of the files in
21
the project. Use::
22

  
12 23
    mvn -Dlicense.quiet=false license:check
13 24

  
14
- How to skip license check from command line::
25
How to skip license check from command line
26
----------------------------------------------
15 27

  
28
If in the project is enabled by default the checking of the headers
29
of files, you can skip this setting the property "license.skip" to
30
true in the command line::
31

  
16 32
    mvn -Dlicense.skip=true install
17 33

  
18
- How to skip attach sources in jar from command line::
34
How to skip attach sources in jar from command line
35
------------------------------------------------------
19 36

  
37
If in the project is enabled by default the generation of jar whith 
38
the sources of the project, you can disable this setting the property
39
"source.skip" to true in the command line::
40

  
20 41
    mvn -Dsource.skip=true  install
21 42

  
22
- How to skip test compile from command line::
43
How to skip test compile from command line
44
--------------------------------------------
23 45

  
46
You can skip the compilation of test setting the propety "maven.test.skip" 
47
to true in the command line::
48

  
24 49
    mvn -Dmaven.test.skip=true  install
25 50

  
26
- How to skip test execution from command line::
27 51

  
52
How to skip test execution from command line
53
----------------------------------------------
54

  
55
You can skip the tests execution setting the propety "skipTests" to true
56
in the command line::
57

  
28 58
    mvn -DskipTests install
29 59

  
30
- How to skip javadoc generation from command line::
60
How to skip javadoc generation from command line
61
--------------------------------------------------
31 62

  
63
You can skip the javadoc generation setting the property
64
"maven.javadoc.skip" to true in the command line::
65

  
32 66
    mvn -Dmaven.javadoc.skip=true  install
33 67

  
34
- How to skip test signature cheks from command line::
68
How to skip test signature cheks from command line
69
---------------------------------------------------
35 70

  
71
You can skip the signature check setting the property
72
"animal.sniffer.skip" to true in the command line::
73

  
36 74
    mvn -Danimal.sniffer.skip=true install
37 75

  
38
- How to install a project without install submodules
76
How to install a project without install submodules
77
----------------------------------------------------------
39 78

  
79
To install a project with submodules and only install the
80
parent project without submodules use the option "--non-recursive" ::
81

  
40 82
    mvn --non-recursive install
41 83

  
42
- How to check and fix the header of source files.
84
How to check and fix the header of source files.
85
--------------------------------------------------
43 86

  
44
  To check the header use::
87
You can check the headers of the files in you project 
88
using the goal "license". To check the header use::
89

  
90
  mvn license:check
91

  
92
To fix the header use::
93

  
94
  mvn license:format
45 95
  
46
    mvn license:check
47
  
48
  To fix the header use::
49
  
50
    mvn license:format
51
  
52
- How to skip test compilation::
96
How to skip test compilation
97
--------------------------------
53 98

  
54
    <build>
55
      <plugins>
56
        ...
57
        <plugin>
58
          <!-- Skip compilation tests -->
59
          <groupId>org.apache.maven.plugins</groupId>
60
          <artifactId>maven-compiler-plugin</artifactId>
61
          <executions>
62
            <execution>
63
              <id>default-testCompile</id>
64
              <phase>process-test-sources</phase>
65
              <goals>
66
                <goal>testCompile</goal>
67
              </goals>
68
              <configuration>
69
                <skip>true</skip>
70
              </configuration>
71
            </execution>
72
          </executions>
73
        </plugin>
74
        ...
75
      </plugins>
76
    </build>
99
To configure a project to don't run the compilation
100
of test you can add to this pom the next configuration of
101
the plugin "maven-compiler-plugin"::
77 102

  
78
- Skip test execution::
103
  <build>
104
    <plugins>
105
      ...
106
      <plugin>
107
        <!-- Skip compilation tests -->
108
        <groupId>org.apache.maven.plugins</groupId>
109
        <artifactId>maven-compiler-plugin</artifactId>
110
        <executions>
111
          <execution>
112
            <id>default-testCompile</id>
113
            <phase>process-test-sources</phase>
114
            <goals>
115
              <goal>testCompile</goal>
116
            </goals>
117
            <configuration>
118
              <skip>true</skip>
119
            </configuration>
120
          </execution>
121
        </executions>
122
      </plugin>
123
      ...
124
    </plugins>
125
  </build>
79 126

  
80
    <build>
81
      <plugins>
82
        ...
83
        <plugin>
84
          <!-- Skip test execution -->
85
          <groupId>org.apache.maven.plugins</groupId>
86
          <artifactId>maven-surefire-plugin</artifactId>
87
          <configuration>
88
            <skipTests>true</skipTests>
89
          </configuration>
90
        </plugin>
91
        ...
92
      </plugins>
93
    </build>
127
Skip test execution
128
----------------------
94 129

  
95
- Continue on test failure :: 
130
To configure a project to don't run the execution
131
of test you can add to this pom the next configuration of
132
the plugin "maven-surefire-plugin"::
96 133

  
97
    <build>
98
      <plugins>
99
        ...
100
        <plugin>
101
          <!-- Continue on test failure -->
134

  
135
  <build>
136
    <plugins>
137
      ...
138
      <plugin>
139
        <!-- Skip test execution -->
140
        <groupId>org.apache.maven.plugins</groupId>
141
        <artifactId>maven-surefire-plugin</artifactId>
142
        <configuration>
143
          <skipTests>true</skipTests>
144
        </configuration>
145
      </plugin>
146
      ...
147
    </plugins>
148
  </build>
149

  
150
Continue on test failure
151
-----------------------------
152

  
153
You can configure a project to continue on test execution 
154
failure. To do this add to the pom of the project the next 
155
configuration of plugin "maven-surefire-plugin" ::
156

  
157
  <build>
158
    <plugins>
159
      ...
160
      <plugin>
161
        <!-- Continue on test failure -->
162
        <groupId>org.apache.maven.plugins</groupId>
163
        <artifactId>maven-surefire-plugin</artifactId>
164
        <configuration>
165
          <testFailureIgnore>true</testFailureIgnore>
166
        </configuration>
167
      </plugin>
168
      ...
169
    </plugins>
170
  </build>
171

  
172

  
173
Set java compatibility
174
--------------------------
175

  
176
To set the compatibility with a java version  add to the 
177
pom of the project the next configuration of plugin 
178
"maven-compiler-plugin" ::
179

  
180
  <build>
181
    <plugins>
182
      ...
183
      <plugin>
184
          <!-- Set java compatibility -->
102 185
          <groupId>org.apache.maven.plugins</groupId>
103
          <artifactId>maven-surefire-plugin</artifactId>
186
          <artifactId>maven-compiler-plugin</artifactId>
104 187
          <configuration>
105
            <testFailureIgnore>true</testFailureIgnore>
188
              <source>1.5</source>
189
              <target>1.5</target>
190
              <encoding>ISO-8859-1</encoding>
106 191
          </configuration>
107
        </plugin>
108
        ...
109
      </plugins>
110
    </build>
192
      </plugin>
193
      ...
194
    </plugins>
195
  </build>
111 196

  
197
Packaging tests in jar
198
------------------------
112 199

  
113
- Set java compatibility::
200
Test classes do not packaging in jar by default.
201
To packing add to pom::
114 202

  
115
    <build>
116
      <plugins>
117
        ...
118
        <plugin>
119
            <!-- Set java compatibility -->
120
            <groupId>org.apache.maven.plugins</groupId>
121
            <artifactId>maven-compiler-plugin</artifactId>
203
  <build>
204
    <plugins>
205
      ...
206
      <plugin>
207
        <!-- Packaging tests in jar -->
208
        <groupId>org.apache.maven.plugins</groupId>
209
        <artifactId>maven-jar-plugin</artifactId>
210
        <executions>
211
          <!-- Generates a jar file only with the test classes -->
212
          <execution>
213
            <goals>
214
              <goal>test-jar</goal>
215
            </goals>
122 216
            <configuration>
123
                <source>1.5</source>
124
                <target>1.5</target>
125
                <encoding>ISO-8859-1</encoding>
217
              <includes>
218
                <include>**/**</include>
219
              </includes>
126 220
            </configuration>
127
        </plugin>
128
        ...
129
      </plugins>
130
    </build>
221
          </execution>
222
        </executions>
223
      </plugin> 
224
      ...
225
    </plugins>
226
  </build>
131 227

  
132
- Packaging tests in jar
228
How to set a dependency with tests jar
229
-----------------------------------------
133 230

  
134
  Test classes do not packaging in jar by default.
135
  To packing add to pom::
231
You can set a dependency with a test jar adding to
232
the declaration of the dependency the scope of
233
test and the type of "test-jar"::
136 234

  
137
    <build>
138
      <plugins>
139
        ...
140
        <plugin>
141
          <!-- Packaging tests in jar -->
142
          <groupId>org.apache.maven.plugins</groupId>
143
          <artifactId>maven-jar-plugin</artifactId>
144
          <executions>
145
            <!-- Generates a jar file only with the test classes -->
146
            <execution>
147
              <goals>
148
                <goal>test-jar</goal>
149
              </goals>
150
              <configuration>
151
                <includes>
152
                  <include>**/**</include>
153
                </includes>
154
              </configuration>
155
            </execution>
156
          </executions>
157
        </plugin> 
158
        ...
159
      </plugins>
160
    </build>
235
  <dependency>
236
      <groupId>...</groupId>
237
      <artifactId>...</artifactId>
238
      <type>test-jar</type>
239
      <scope>test</scope>
240
  </dependency>
161 241

  
162
- How to set a dependency with tests jar::
242
How use ant in maven
243
-------------------------
163 244

  
164
    <dependency>
165
        <groupId>...</groupId>
166
        <artifactId>...</artifactId>
167
        <type>test-jar</type>
168
        <scope>test</scope>
169
    </dependency>
245
You can use ant embed in the pom of you project.
246
To do this use::
170 247

  
171
- How use ant in maven::
248
  <plugin>
249
    <artifactId>maven-antrun-plugin</artifactId>
250
    <version>1.7</version>
251
    <executions>
252
      <execution>
253
        <phase>generate-sources</phase>
254
        <configuration>
255
          <target>
256
            <echo>Hello world!</echo>
257
          </target>
258
        </configuration>
259
        <goals>
260
          <goal>run</goal>
261
        </goals>
262
      </execution>
263
    </executions>
264
  </plugin>
172 265

  
173
    <plugin>
174
      <artifactId>maven-antrun-plugin</artifactId>
175
      <version>1.7</version>
176
      <executions>
177
        <execution>
178
          <phase>generate-sources</phase>
179
          <configuration>
180
            <target>
181
              <echo>Hello world!</echo>
182
            </target>
183
          </configuration>
184
          <goals>
185
            <goal>run</goal>
186
          </goals>
187
        </execution>
188
      </executions>
189
    </plugin>
266
Fail when execute "mvn deploy" with "No connector available"
267
-------------------------------------------------------------
190 268

  
191
- Fail when execute "mvn deploy" with the error::
269
When execute a "mvn deploy" fail with the error::
192 270

  
193
    [INFO] ------------------------------------------------------------------------
194
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project org.gvsig.desktop: Failed to deploy artifacts/metadata: No connector available to access repository gvsig-repository (dav:https://devel.gvsig.org/m2repo/j2se) of type default using the available factories WagonRepositoryConnectorFactory -> [Help 1]
195
    [ERROR] 
196
    
197
  This happens to be configured the webdav wagon as an extension in the section "build"::
271
  [INFO] ------------------------------------------------------------------------
272
  [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy 
273
    (default-deploy) on project org.gvsig.desktop: Failed to deploy artifacts/metadata: 
274
    No connector available to access repository gvsig-repository (dav:https://devel.gvsig.org/m2repo/j2se) 
275
    of type default using the available factories WagonRepositoryConnectorFactory -> [Help 1]
276
  [ERROR] 
198 277
  
199
    ...
200
    <build>
201
      <extensions>
202
          <extension>
203
              <groupId>org.apache.maven.wagon</groupId>
204
              <artifactId>wagon-webdav-jackrabbit</artifactId>
205
              <version>1.0-beta-7</version>
206
          </extension>
207
      </extensions>
208
    ...
209
    
278
This happens to be configured the webdav wagon as an extension in the section "build"::
279

  
280
  ...
281
  <build>
282
    <extensions>
283
        <extension>
284
            <groupId>org.apache.maven.wagon</groupId>
285
            <artifactId>wagon-webdav-jackrabbit</artifactId>
286
            <version>1.0-beta-7</version>
287
        </extension>
288
    </extensions>
289
  ...
290

  
291
Fail when execute "mvn release: prepare" with "svn command failed... Could not authenticate"
292
------------------------------------------------------------------------------------------------
293

  
294
When running "mvn release: prepare" updates poms, compiles, and then
295
fails with the following error ::
296

  
297
  [INFO] ------------------------------------------------------------------------
298
  [ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.1:prepare 
299
    (default-cli) on project org.gvsig.desktop: Unable to commit files
300
  [ERROR] Provider message:
301
  [ERROR] The svn command failed.
302
  [ERROR] Command output:
303
  [ERROR] svn: Commit failed (details follow):
304
  [ERROR] svn: MKACTIVITY of '/svn/gvsig-desktop/!svn/act/931a27bc-57e8-45d9-adcd-5a2cf54a7045': 
305
    authorization failed: Could not authenticate to server: rejected Basic challenge (https://devel.gvsig.org)
306
  [ERROR] -> [Help 1]
307
  [ERROR] 
308
  [ERROR]
309

  
310
Apparently maven in linux system use the svn of system and if you're not
311
authenticated when trying to access to the repository, svn fails.
312

  
313
This is solved by executing a commit from the command line on
314
some file of the project (only if you have not enabled the option 
315
"store-passwords = no" in $ HOME / .subversion / config). For example, you 
316
can add or remove at the end of "pom.xml" a blank line and then run 
317
from the command line ::
318

  
319
  svn ci -m "" pom.xml
320

  

Also available in: Unified diff