是否可以將整個目錄及其中的所有子目錄上傳/下載到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的
- 4. 使用Python通過FTP下載整個目錄
- 5. 上傳到Nexus
- 6. 如何使用Gradle將依賴項Artifact上傳到Maven Repository(NEXUS)?
- 7. 如何通過Maven將zip文件部署到Nexus存儲庫
- 8. 如何將整個目錄上傳到S3?
- 9. 從命令行通過FTP下載完整的遠程目錄
- 10. 我們如何將整個目錄複製到maven中的另一個目錄?
- 11. 使用maven從nexus下載war文件
- 12. Maven:將神器及其代碼下載到特定目錄
- 13. 如何下載整個目錄?
- 14. 在Python下載整個目錄SimpleHTTPServer
- 15. 使用Maven將依賴關係下載到命令行上的目錄中
- 16. 上傳到多個目錄
- 17. FTP通過PHP上傳和下載
- 18. 如何使用python上的Maven上傳到Nexus
- 19. 如何將.jar上傳到S3並通過maven使用它?
- 20. Maven從url下載或獲取wsdl到項目目錄
- 21. 用maven和nexus編譯時卡在下載工件上
- 22. 如何將JAR上傳到Nexus OSS 3?
- 23. Jenkins將神器上傳到nexus插件
- 24. 使用Apache Commons FTP庫在Android上通過FTP下載目錄
- 25. Python:通過argparse傳遞一個目錄
- 26. Jenkins配置文件Maven多個Nexus存儲庫下載
- 27. 上傳工件到Nexus 3
- 28. Gradle上傳android應用程序apk到maven回購(nexus)
- 29. Maven發佈:有沒有辦法阻止模塊上傳到Nexus?
- 30. 未能通過Nexus代理到maven回購
闡述會是這樣一個現有的maven回購或一些任意文件? – 2010-07-21 16:34:57
對於上傳到Nexus服務器,這是針對任意文件。 對於從服務器下載,我想這將從Nexus存儲庫。 – Peter 2010-08-24 20:24:55