Why does Maven run tests again when the JAR already exists?

I installmy maven project:

mvn clean install

Everything works fine, a JAR file is created in the directory /target. Now I run it again:

mvn install

Maven performs unit tests and static code analysis again . I did not make any changes to the files .java, and the JAR is there, so why run the tests again? Am I doing something wrong, or how does maven work?

+3
source share
3 answers

Now I run it again (...) Maven performs unit tests and static code analysis again

Because this is just what you are asking Maven.

, Maven , . , :

mvn install

, install (validate, compile, test, package ..) install, , .

Maven Java, .

, /:

  • install, ?
  • , .

. mvn clean install, java . mvn install , maven / , . , .

, mvn install , mvn install , . , , , , (AFAIK, - , ).

.

. :

-rf, --resume-from
        Resume reactor from specified project
-pl, --projects
        Build specified reactor projects instead of all projects
-am, --also-make
        If project list is specified, also build projects required by the list
-amd, --also-make-dependents
        If project list is specified, also build projects that depend on projects on the list 

, - ( , module-foo):

mvn -pl module-foo,my-packaged-app install

, , module-foo:

mvn -pl module-foo -amd install
+5

, maven install. , , , , .

( , ), compiler, mvn compile, jar mvn jar:jar.

: mvn -Dmaven.test.skip=true install.

+4

'test' - 'build'. , pom.xml,

<build>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
        <skipTests>true</skipTests>
        </configuration>
    </plugin>
   </build> 

And then create the "test" profile, which will contain the test configuration. If you want to run tests, run mvn -Ptest test.

As the dog has already answered, you cannot skip in any other way.

+2
source

Source: https://habr.com/ru/post/1772628/


All Articles