It is a small story that is often useful when actually working.
I think everyone often skips running tests with -DskipTests
at build time (?).
Similarly, you can skip the test execution with -Dmaven.test.skip
, but this also skips the compilation of the test code, so it's okay if the test code has a compilation error (??).
Furthermore, if the test
scope dependency is broken even after executing mvn package -Dmaven.test.skip
(dependency cannot be resolved. In rare cases, such as a project that refers to a repository other than Maven Central. Yes) will result in a build error.
In that case, do not mvn package
, but mvn compile jar: jar
(if packaging
is war
, war: war
instead of jar: jar
) will make the test
scope dependency. It's okay because it builds without solving it (???).
If the -e
option is added, a stack trace will be output when the build fails.
Experience shows that Maven often cannot be identified immediately by looking at the stack trace, but it's better than nothing, so basically it's a good idea to add the -e
option.
Then add the -X
option and the debug log will be output.
Since a large amount of logs are output and it is difficult to go back to the console, it is recommended to write to a log file together with the -l
option.
It's like this.
mvn -X -l maven.log test
If you want to read Maven code during the investigation, you can get it from https://github.com/apache/maven.
When deploying a JAR or WAR to a Maven repository such as Nexus, Maven reads the credentials of the server to which it is deployed from settings.xml
.
When deploying with CI/CD tool, put the following settings.xml
in the same location as the source code and specify it with the -s
option (command example mvn -s settings.xml deploy
). There is.
<settings>
<servers>
<server>
<id>nexus</id>
<username>deployuser</username>
<password>deploypassword</password>
</server>
</profiles>
</settings>
If you don't want to hard-code the password, you can read it from the environment variable by setting the password
element as follows.
<password>${env.DEPLOY_PASSWORD}</password>
In this case, read the password from the environment variable DEPLOY_PASSWORD
.
Some CI/CD tools set secret information in environment variables at build time, but this is a method that can be used in such an environment.
You can also encrypt your password if you don't want to hardcode it in your local settings.xml
.
See the Password Encryption (https://maven.apache.org/guides/mini/guide-encryption.html) section of the official Maven documentation for more information.
You can get help for the mvn
command with mvn --help
, but you can list the goals of the plugin with mvn <plugin>: help
.
For example, running mvn compiler: help
will give you the following output:
[INFO] Apache Maven Compiler Plugin 3.8.0
The Compiler Plugin is used to compile the sources of your project.
This plugin has 3 goals:
compiler:compile
Compiles application sources
compiler:help
Display help information on maven-compiler-plugin.
Call mvn compiler:help -Ddetail=true -Dgoal=<goal-name> to display parameter
details.
compiler:testCompile
Compiles application test sources.
You can also see more details about a particular goal, as described in compiler: help
.
You can see the parameter description in the goal details.
Useful when writing plugin settings ... I don't know which is faster and more convenient to google the plugin and get to the official docs!
Also, maven-help-plugin may be useful, so I recommend keeping the existence in the corner of your head (I'm exhausted, so I'll omit the explanation ...).
When I'm actually moving my hands, I feel like I'm doing more, but for the time being, this is the small story I can remember when I'm relaxing.
that's all.
Recommended Posts