How to create self-maven source distribution maven?

What I want to do is create a source distribution of my application with all the dependencies and burn it to a DVD. So that I can build it in 100 years (well, well, you know what I mean ...). No online dependencies on maven libraries or plugins!

I know that Ant will be better for this, but I use maven in my project. I am not going to switch to Ant just for this, I ask how to do it with maven. Or, if there is a way to create a stand-alone Ant build that I could put on a DVD, that would be great too. (there is a plugin ant:ant, but it just generates Ant build.xml, which indicates dependencies on the local maven repository)

The approach I made was that I wanted to create a special local repository that can be placed on a DVD, and then build the project using mvn -o -Dmaven.repo.local=repo/on/dvd. I tried to create such a repository with dependency:copy-dependenciesand options useRepositoryLayoutset to true. But it does not copy freaking maven plugins which depend on my build ...

+3
source share
3 answers

The only way I can enable plugins is to specify a different local repository to build on the command line and ensure that all dependency sources, etc. are loaded, and then create an archive, including the contents of the project and the user repository.

pom, javadocs ( , , ). ( ) .

, - , , . , mvn clean. , :

mvn package -Parchive -Dmaven.repo.local=.\target\repo

pom:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>name.seller.rich</groupId>
  <artifactId>test-archive</artifactId>
  <version>0.0.1</version>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.5</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <profiles>
    <profile>
      <id>archive</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
              <execution>
                <id>sources</id>
                <phase>pre-package</phase>
                <goals>
                  <goal>copy-dependencies</goal>
                </goals>
                <configuration>
                  <classifier>sources</classifier>
                  <failOnMissingClassifierArtifact>false</failOnMissingClassifierArtifact>
                  <!--the target directory won't be included, but the sources will be in the repository-->
                  <outputDirectory>${project.build.directory}/sources</outputDirectory>
                </configuration>
              </execution>
              <execution>
                <id>javadocs</id>
                <phase>pre-package</phase>
                <goals>
                  <goal>copy-dependencies</goal>
                </goals>
                <configuration>
                  <classifier>javadoc</classifier>                      <failOnMissingClassifierArtifact>false</failOnMissingClassifierArtifact>
                  <outputDirectory>${project.build.directory}/javadocs</outputDirectory>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.2-beta-4</version>
            <executions>
              <execution>
                <phase>package</phase>
                <goals>
                  <goal>single</goal>
                </goals>
                <configuration>
                  <descriptors>
                    <descriptor>src/main/assembly/archive.xml</descriptor>
                  </descriptors>
                </configuration>
              </execution>
            </executions>
          </plugin>    
        </plugins>
      </build>
    </profile>
  </profiles>
</project>

:

<assembly>
  <id>archive</id>
  <formats>
    <format>zip</format>
  </formats>
  <fileSets>
    <fileSet>
     <directory>${project.basedir}</directory>
     <outputDirectory>/</outputDirectory>
      <excludes>
        <exclude>target/**</exclude>
      </excludes>
    </fileSet>
    <fileSet>
     <directory>${maven.repo.local}</directory>
     <outputDirectory>repo</outputDirectory>
    </fileSet>
  </fileSets>
</assembly>
+3

: Maven

:

Maven, , ? .

. - .

+1

. , , , ( ) mvn dependency: go .

, maven JDK . , , maven.

0

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


All Articles