How to create a download site using maven

I am new to Maven and trying to accomplish a simple task:

  • create jar package and website [DONE]
  • deploy them to a remote server using scp [DONE]
  • the site should contain a download page with links to the deployed jar files [MISSING]

I do not want to use archiva or similar tools. I just want to have a (static, generated) page on the website with links to all the built-in banks (or just the latest build).

I tried:

  • put <item name="Downloads" href="download.html"/>in site.xml
  • mvn commons:download-page
  • mvn deploy site:deploy

What I get: these commands copy the jar file to the remote server:

{deploy-dir}/com.acme.etc/ArtifactID/0.0.2-SNAPSHOT/ArtifactID-0.0.2-SNAPSHOT.jar

generated download page points to

{deploy-dir}/target/site/[preferred]/commons/ArtifactID/binaries/ArtifactID-bin.tar.gz

, [if-any logo][end]. , script html. , .

, (, ), , , .

.

+3
2

(...) jar [MISSING]

, , , (commons-build-plugin Apache Commons).

, Maven, Maven latests. , Maven. :

.. 2.0--6 .

, .vm .

, Maven - src/site/apt/download.apt.vm, ${currentVersion} , POM

.. . Velocity dot-notation .

POM

<properties>
  <!-- This will not work because the name of the property has a dot in it -->
  <my.property>My value</my.property>
  <!-- This will work because the name of the property has no dot in it -->
  <myProperty>My other value</myProperty>
</properties>

${my.property} , . ${myProperty} .

0

. pom groovy script, deploy: deploy-file

<properties>

    <!-- The base URL of your repository -->
    <linkpage.repobaseurl>http://www.my.maven.repo/public</linkpage.repobaseurl>

    <!-- The download page file -->
    <linkpage.file>${project.build.directory}/downloadpage.html</linkpage.file>
</properties>
<build>
    <plugins>

        <plugin>
            <groupId>org.codehaus.groovy.maven</groupId>
            <artifactId>gmaven-plugin</artifactId>
            <version>1.0</version>
            <executions>
                <execution>
                    <id>build-links</id>
                    <phase>deploy</phase>
                    <goals>
                        <goal>execute</goal>
                    </goals>
                    <configuration>
                        <source>
                            <![CDATA[
def uniqueVersion = null;
pom.artifact.metadataList.each{
    if(it.class.simpleName=='ProjectArtifactMetadata'){
        def afi = it.class.superclass.getDeclaredField('artifact');
        afi.accessible = true;
        // this is the final version we need for the URLs
        uniqueVersion = it.artifact.version;
    }
};
def repoBase = pom.properties['linkpage.repobaseurl'];
def downloadPage = new File(pom.properties['linkpage.file']);

// build list of artifacts
def listOfArtifacts = [];
// main artifact
listOfArtifacts.add(pom.artifact);
// attached artifacts like sources, javadocs etc
listOfArtifacts.addAll(pom.attachedArtifacts);

def str = '';
listOfArtifacts.each{
    def cls = it.classifier != null ? '-' + it.classifier : '';
    def vers = (uniqueVersion != null ? uniqueVersion : it.version);
    def parentPath = "${repoBase}/${ pom.groupId.replace( '.' , '/' )}/${pom.artifactId}/${pom.version}/" 
    def path = "${parentPath}${pom.artifactId}-${vers}${cls}.${it.type}" 

    // build the link using a here document
    str += """
<a href="${path}">${it}</a><br />
"""     
}

// now build the page using a here document
downloadPage.text="""
<html>
<head>
<title>Download page for ${project.artifact}</title>
</head>
<body>
<h1>Downloads</h1>
${str}
</body>
</html>
""";
                                    ]]>
                        </source>
                    </configuration>
                </execution>

            </executions>
        </plugin>

        <!-- now we need to manually deploy the download page using deploy:deploy-file -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-deploy-plugin</artifactId>
            <version>2.5</version>
            <executions>
                <execution>
                    <phase>deploy</phase>
                    <id>deploy-downloadpage</id>
                    <goals>
                        <goal>deploy-file</goal>
                    </goals>
                    <configuration>
                        <file>${linkpage.file}</file>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>${project.artifactId}</artifactId>
                        <version>${project.version}</version>
                        <classifier>download</classifier>
                        <packaging>html</packaging>
                        <uniqueVersion>false</uniqueVersion>
                        <url>${project.distributionManagement.repository.url}</url>
                        <repositoryId>${project.distributionManagement.repository.id}</repositoryId>

                    </configuration>
                </execution>
            </executions>
            <configuration>
            </configuration>
        </plugin>
    </plugins>
</build>
+1

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


All Articles