[JAVA] Operate Maven dependent modules

Operate Maven dependent modules

I'm having trouble using a module whose source is public but not in the Maven repository, so a note of the command to handle the dependencies.

--For example, Module for hitting Notification Hubs in Azure

--Reference

Generate jar

--Create a jar file in the target folder.

$ mvn package

--Source and Javadoc jar file generation

$ mvn source:jar javadoc:jar

Skip the test

--Use maven.test.skip property --Can be specified from the command line with the -D option.

$ mvn package -Dmaven.test.skip=true

Create fat jar (uber-jar)

--Combine dependent modules into one jar. ――Use the ʻassemblyplugin (orshade). --Here, ʻassembly is used.

pom.xml

--ʻAssemblyAdd the plugin and set the descriptorjar-with-dependencies`.

<build>
  [...]
  <plugins>
    [...]
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <version>3.0.0</version>
      <configuration>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
      </configuration>
      <executions>
        <execution>
          <id>make-assembly</id>
          <phase>package</phase>
          <goals>
            <goal>single</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

--The package command outputs * -jar-with-dependencies.jar to the target folder. --A normal jar file is also output.

$ mvn package

Download dependent libraries

Download to any folder

--Download the dependent modules with dependency: copy-dependencies. --By default, download to ./target/dependency. --You can change the download destination folder with the ʻoutputDirectoryproperty. --Specify the download of the source file and Javadoc with theclassifier` property. --Other options: http://maven.apache.org/plugins/maven-dependency-plugin/copy-dependencies-mojo.html

$ mvn dependency:copy-dependencies
$ mvn dependency:copy-dependencies -Dclassifier=sources
$ mvn dependency:copy-dependencies -Dclassifier=javadoc

Download to local repository

--Default local repository

$ mvn dependency:go-offline

Recommended Posts

Operate Maven dependent modules
maven
Use Maven only for downloading dependent libraries