是否可以将整个目录及其中的所有子目录上传/下载到Nexus存储库服务器/从Nexus存储库服务器下载整个目录?通过Maven将整个目录上传/下载到Nexus
回答
如果你想实际部署文件的层次结构,我使用GMaven(在maven中嵌入groovy)攻击了一个解决方案。
使用下面的pom,提供一些属性并点击mvn install
。 该文件夹将被抓取,其中的所有文件都将使用从相对路径获取的artifactId进行部署。例如
鉴于基本文件夹
c:\a\b\c
文件
c:\a\b\c\def\ghi\jkl.mno
将有artifactId的def-ghi-jkl
和包装mno
,这当然可以改成别的东西。
存储库信息将取自pom,因此您需要在pom中提供distributionManagement元素。
这是(很多这样的代码是从deploy:deploy-file魔力拍摄):
<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>com.mycompany</groupId>
<artifactId>folderdeployer</artifactId>
<packaging>jar</packaging>
<version>SNAPSHOT</version>
<properties>
<!-- This is where your artifacts are -->
<deploy.basefolder>c:\temp\stuff</deploy.basefolder>
<!-- This will be used as groupId -->
<deploy.groupId>my.groupid</deploy.groupId>
<!-- this will be used as version -->
<deploy.version>1.2.3</deploy.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>deploy-files</id>
<phase>prepare-package</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
<![CDATA[
// read components from plexus container
def layout = session.lookup(
'org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout');
def repoFactory = session.lookup(
'org.apache.maven.artifact.repository.ArtifactRepositoryFactory');
def repository = repoFactory.createDeploymentArtifactRepository(
pom.distributionManagement.repository.id,
pom.distributionManagement.repository.url,
layout, true);
def localRepository = session.localRepository;
def helper =
session.lookup("org.apache.maven.project.MavenProjectHelper");
def afm = session.lookup(
'org.apache.maven.artifact.handler.manager.ArtifactHandlerManager');
def factory = new org.apache.maven.artifact.factory.DefaultArtifactFactory();
factory.class.getDeclaredField("artifactHandlerManager").accessible = true;
factory.artifactHandlerManager=afm;
def deployer = session.lookup(
'org.apache.maven.artifact.deployer.ArtifactDeployer');
// initialize properties
def baseFolder = new File(pom.properties['deploy.basefolder']);
def groupId = pom.properties['deploy.groupId'];
def version = pom.properties['deploy.version'];
// iterate over all files recursively
baseFolder.eachFileRecurse{
if(it.isDirectory())return;
// packaging = file.extension
def packaging = it.name.replaceAll(/.+\./ , '');
// artifactId = file.relativePath.replace '/' , '-'
def artifactId = it.absolutePath
.replace(baseFolder.absolutePath, '')
.substring(1)
.replaceFirst(/\..*?$/ , '')
.replaceAll(/\W+/ , '-');
def artifact =
factory.createBuildArtifact(
groupId, artifactId, version, packaging);
// create pom for artifact
def model = new org.apache.maven.model.Model();
model.setModelVersion("4.0.0");
model.setGroupId(groupId);
model.setArtifactId(artifactId);
model.setVersion(version);
model.setPackaging(packaging);
File pomFile = File.createTempFile("mvndeploy", ".pom");
pomFile.deleteOnExit();
fw = org.codehaus.plexus.util.WriterFactory.newXmlWriter(pomFile);
new org.apache.maven.model.io.xpp3.MavenXpp3Writer().write(fw, model);
org.apache.commons.io.IOUtils.closeQuietly(fw);
def metadata =
new org.apache.maven.project.artifact.ProjectArtifactMetadata(
artifact, pomFile);
artifact.addMetadata(metadata);
// deploy file
deployer.deploy(it, artifact, repository, localRepository);
}
]]>
</source>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>your repo id here</id>
<url>scp://your.repo.url/here</url>
<layout>default</layout>
</repository>
</distributionManagement>
</project>
编辑:
我对这个on my blog
有趣的,我会研究它。谢谢! – Peter 2010-08-24 20:29:31
有帮助!我修改它以适应本地存储库文件夹结构。 https://gist.github.com/aleung/5194777 – aleung 2013-03-19 09:35:34
我们已经使用@aleung脚本的修改版本将近一年,现在没有问题 修改了处理'maven-metadata.xml'和'.sha'和'.md5'文件可以在分叉要点中找到:https://gist.github.com/jakub-bochenski/7802ee7f44b8e3b99bdd69b2ab150e6c – 2017-11-29 16:31:06
- 1. 通过PHP FTP上传整个目录
- 2. 将工件上传到Nexus,无需Maven
- 3. Maven:上传和下载zip文件到nexus存储库
- 4. 通过PHP将整个目录通过PHP上传到远程主机通过FTP
- 5. 下载项目通过Maven的
- 6. 使用Python通过FTP下载整个目录
- 7. 是否可以通过FTP下载整个目录?
- 8. maven deploy - 只上传ear文件到nexus
- 9. 通过FTP上传整个目录在VB.NET
- 10. Nexus不通过Hudson下载文物
- 11. 上传到Nexus
- 12. 如何通过Maven将zip文件部署到Nexus存储库
- 13. 如何将maven插件上传到Nexus存储库?
- 14. 如何使用Gradle将依赖项Artifact上传到Maven Repository(NEXUS)?
- 15. 如何将整个目录上传到S3?
- 16. Maven项目上传到谷歌代码“下载”选项卡
- 17. 从命令行通过FTP下载完整的远程目录
- 18. 我们如何将整个目录复制到maven中的另一个目录?
- 19. Maven:将神器及其代码下载到特定目录
- 20. 通过FTP自动下载目录
- 21. 使用maven从nexus下载war文件
- 22. 如何下载整个目录?
- 23. 使用FTP4J下载整个目录
- 24. 在Python下载整个目录SimpleHTTPServer
- 25. 上传到多个目录
- 26. 使用Maven将依赖关系下载到命令行上的目录中
- 27. Apatana不通过FTP上传子目录?
- 28. FTP通过PHP上传和下载
- 29. C#使用FTP上传整个目录
- 30. 在django上传整个目录
阐述会是这样一个现有的maven回购或一些任意文件? – 2010-07-21 16:34:57
对于上传到Nexus服务器,这是针对任意文件。 对于从服务器下载,我想这将从Nexus存储库。 – Peter 2010-08-24 20:24:55