svn-gvsig-desktop / trunk / org.gvsig.desktop / maven-howto.rst @ 40533
History | View | Annotate | Download (9.29 KB)
1 | 40435 | jjdelcerro | |
---|---|---|---|
2 | 40513 | jjdelcerro | ================================== |
3 | Usefull maven "howtos" and FAQs |
||
4 | ================================== |
||
5 | 40471 | jjdelcerro | |
6 | 40513 | jjdelcerro | .. contents:: |
7 | 40435 | jjdelcerro | |
8 | 40513 | jjdelcerro | How to reduce the process of "install" to run as fast as possible. |
9 | ------------------------------------------------------------------- |
||
10 | 40435 | jjdelcerro | |
11 | 40513 | jjdelcerro | Can reduce install execution skiping test execution and compilation, |
12 | javadoc generation, test signature checking, license checking, and |
||
13 | attach sources in jar. |
||
14 | 40471 | jjdelcerro | |
15 | 40513 | jjdelcerro | 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 | |||
23 | 40472 | jjdelcerro | mvn -Dlicense.quiet=false license:check |
24 | 40471 | jjdelcerro | |
25 | 40513 | jjdelcerro | How to skip license check from command line |
26 | ---------------------------------------------- |
||
27 | 40471 | jjdelcerro | |
28 | 40513 | jjdelcerro | 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 | |||
32 | 40471 | jjdelcerro | mvn -Dlicense.skip=true install |
33 | |||
34 | 40513 | jjdelcerro | How to skip attach sources in jar from command line |
35 | ------------------------------------------------------ |
||
36 | 40469 | jjdelcerro | |
37 | 40513 | jjdelcerro | 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 | |||
41 | 40469 | jjdelcerro | mvn -Dsource.skip=true install |
42 | |||
43 | 40513 | jjdelcerro | How to skip test compile from command line |
44 | -------------------------------------------- |
||
45 | 40435 | jjdelcerro | |
46 | 40513 | jjdelcerro | You can skip the compilation of test setting the propety "maven.test.skip" |
47 | to true in the command line:: |
||
48 | |||
49 | 40435 | jjdelcerro | mvn -Dmaven.test.skip=true install |
50 | |||
51 | |||
52 | 40513 | jjdelcerro | 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 | |||
58 | 40435 | jjdelcerro | mvn -DskipTests install |
59 | |||
60 | 40513 | jjdelcerro | How to skip javadoc generation from command line |
61 | -------------------------------------------------- |
||
62 | 40435 | jjdelcerro | |
63 | 40513 | jjdelcerro | You can skip the javadoc generation setting the property |
64 | "maven.javadoc.skip" to true in the command line:: |
||
65 | |||
66 | 40435 | jjdelcerro | mvn -Dmaven.javadoc.skip=true install |
67 | |||
68 | 40513 | jjdelcerro | How to skip test signature cheks from command line |
69 | --------------------------------------------------- |
||
70 | 40435 | jjdelcerro | |
71 | 40513 | jjdelcerro | You can skip the signature check setting the property |
72 | "animal.sniffer.skip" to true in the command line:: |
||
73 | |||
74 | 40435 | jjdelcerro | mvn -Danimal.sniffer.skip=true install |
75 | |||
76 | 40513 | jjdelcerro | How to install a project without install submodules |
77 | ---------------------------------------------------------- |
||
78 | 40435 | jjdelcerro | |
79 | 40513 | jjdelcerro | To install a project with submodules and only install the |
80 | parent project without submodules use the option "--non-recursive" :: |
||
81 | |||
82 | 40435 | jjdelcerro | mvn --non-recursive install |
83 | |||
84 | 40513 | jjdelcerro | How to check and fix the header of source files. |
85 | -------------------------------------------------- |
||
86 | 40469 | jjdelcerro | |
87 | 40513 | jjdelcerro | 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 |
||
95 | 40469 | jjdelcerro | |
96 | 40513 | jjdelcerro | How to skip test compilation |
97 | -------------------------------- |
||
98 | 40435 | jjdelcerro | |
99 | 40513 | jjdelcerro | 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":: |
||
102 | 40435 | jjdelcerro | |
103 | 40513 | jjdelcerro | <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> |
||
126 | 40435 | jjdelcerro | |
127 | 40513 | jjdelcerro | Skip test execution |
128 | ---------------------- |
||
129 | 40435 | jjdelcerro | |
130 | 40513 | jjdelcerro | 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":: |
||
133 | 40435 | jjdelcerro | |
134 | 40513 | jjdelcerro | |
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 --> |
||
185 | 40435 | jjdelcerro | <groupId>org.apache.maven.plugins</groupId> |
186 | 40513 | jjdelcerro | <artifactId>maven-compiler-plugin</artifactId> |
187 | 40435 | jjdelcerro | <configuration> |
188 | 40513 | jjdelcerro | <source>1.5</source> |
189 | <target>1.5</target> |
||
190 | <encoding>ISO-8859-1</encoding> |
||
191 | 40435 | jjdelcerro | </configuration> |
192 | 40513 | jjdelcerro | </plugin> |
193 | ... |
||
194 | </plugins> |
||
195 | </build> |
||
196 | 40435 | jjdelcerro | |
197 | 40513 | jjdelcerro | Packaging tests in jar |
198 | ------------------------ |
||
199 | 40435 | jjdelcerro | |
200 | 40513 | jjdelcerro | Test classes do not packaging in jar by default. |
201 | To packing add to pom:: |
||
202 | 40435 | jjdelcerro | |
203 | 40513 | jjdelcerro | <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> |
||
216 | 40435 | jjdelcerro | <configuration> |
217 | 40513 | jjdelcerro | <includes> |
218 | <include>**/**</include> |
||
219 | </includes> |
||
220 | 40435 | jjdelcerro | </configuration> |
221 | 40513 | jjdelcerro | </execution> |
222 | </executions> |
||
223 | </plugin> |
||
224 | ... |
||
225 | </plugins> |
||
226 | </build> |
||
227 | 40435 | jjdelcerro | |
228 | 40513 | jjdelcerro | How to set a dependency with tests jar |
229 | ----------------------------------------- |
||
230 | 40435 | jjdelcerro | |
231 | 40513 | jjdelcerro | 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":: |
||
234 | 40435 | jjdelcerro | |
235 | 40513 | jjdelcerro | <dependency> |
236 | <groupId>...</groupId> |
||
237 | <artifactId>...</artifactId> |
||
238 | <type>test-jar</type> |
||
239 | <scope>test</scope> |
||
240 | </dependency> |
||
241 | 40435 | jjdelcerro | |
242 | 40513 | jjdelcerro | How use ant in maven |
243 | ------------------------- |
||
244 | 40435 | jjdelcerro | |
245 | 40513 | jjdelcerro | You can use ant embed in the pom of you project. |
246 | To do this use:: |
||
247 | 40435 | jjdelcerro | |
248 | 40513 | jjdelcerro | <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> |
||
265 | 40435 | jjdelcerro | |
266 | 40513 | jjdelcerro | Fail when execute "mvn deploy" with "No connector available" |
267 | ------------------------------------------------------------- |
||
268 | 40435 | jjdelcerro | |
269 | 40513 | jjdelcerro | When execute a "mvn deploy" fail with the error:: |
270 | 40480 | jjdelcerro | |
271 | 40513 | jjdelcerro | [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] |
||
277 | 40480 | jjdelcerro | |
278 | 40513 | jjdelcerro | 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 |