我对Maven很陌生,我试图完成一项简单的任务:
我不想使用档案或类似的工具。我只想在网站上有一个(静态的,生成的)页面,链接到所有构建的jars (或仅指向最新的构建)。
我试过:
<item name="Downloads" href="download.html"/>放入site.xml中commons:download-pagedeploy site:deploy我得到了什么:这些命令将jar文件复制到远程服务器:
{deploy-dir}/com.acme.etc/ArtifactID/0.0.2-SNAPSHOT/ArtifactID-0.0.2-SNAPSHOT.jar生成的下载页指向
{deploy-dir}/target/site/[preferred]/commons/ArtifactID/binaries/ArtifactID-bin.tar.gz在生成的下载页面中也有一些标签,如[if-any logo][end]。我认为服务器应该执行脚本而不是显示html。但是,我不能这样做,因为服务器不属于我。
我想有一个简单的方法(也许完全不同)来完成这个任务,请您指出如何以最简单,但自动化的方式来完成它。
谢谢。
发布于 2010-07-23 23:44:15
(...)该站点应包含下载页面,其中缺少指向已部署的jar文件的链接。
据我所知,这是不受支持的,而且我也不知道有什么插件可以这样做( commons-build-plugin是阿帕奇公域构建的一个特定插件)。
最好将包括Maven表达式在内的自定义页面添加到Maven站点,并对其进行筛选以生成指向工件的最新版本的链接。这实际上就是Maven站点本身正在做的事情。来自创建内容文档:
过滤 注意:这个特性可以在2.0-Bet-6版本或更高版本的站点插件中使用. 若要将属性筛选为任何受支持的文档格式,请向文件名添加一个
.vm扩展。 例如,Maven网站的模块包含一个src/site/apt/download.apt.vm文件,该文件使用表达式${currentVersion}在POM中的属性集中进行筛选。 注意:速度用于应用过滤。因为速度在内部使用点表示法,所以不能在属性中使用点。 如果在POM中声明这些属性 My值我的其他值 然后在文档中使用表达式${my.property},它将无法工作。如果您使用的是表达式${myProperty},它将运行得很好。
发布于 2010-07-25 06:10:26
部署启动后,项目元数据包含最终版本。下面是一个带有groovy脚本的pom摘录,该脚本基于此元数据构建链接页,然后使用部署:部署-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>https://stackoverflow.com/questions/3320002
复制相似问题