Có thể tải lên/tải xuống toàn bộ thư mục và tất cả các thư mục con bên trong thư mục đến/từ máy chủ lưu trữ Nexus không?Tải lên/Tải toàn bộ thư mục về Nexus qua Maven
Trả lời
Bạn luôn có thể nén thư mục và gửi nó dưới dạng tệp zip. người dùng của thư mục này có thể tải xuống từ Nexus và giải nén bằng cách sử dụng sự phụ thuộc: giải nén.
Trong trường hợp bạn muốn triển khai thực sự phân cấp tệp, tôi đã tấn công cùng nhau một giải pháp bằng cách sử dụng GMaven (groovy được nhúng trong maven).
Sử dụng pom bên dưới, cung cấp một số thuộc tính và nhấn mvn install
. Thư mục sẽ được thu thập thông tin và tất cả các tệp bên trong nó sẽ được triển khai bằng cách sử dụng artifactId được lấy từ đường dẫn tương đối. ví dụ.
Với thư mục cơ sở
c:\a\b\c
file
c:\a\b\c\def\ghi\jkl.mno
sẽ có artifactId def-ghi-jkl
và bao bì mno
, điều này tất nhiên có thể được thay đổi để cái gì khác.
Thông tin kho lưu trữ sẽ được lấy từ pom, vì vậy bạn cần cung cấp phần tử DistributionManagement trong pom.
Ở đây nó được (rất nhiều mã này được lấy từ deploy:deploy-file mojo):
<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>
EDIT:
tôi xây dựng về vấn đề này on my blog
Thú vị, tôi sẽ xem xét nó. Cảm ơn! – Peter
Hữu ích! Tôi đã sửa đổi nó để phù hợp với cấu trúc thư mục kho lưu trữ cục bộ. https://gist.github.com/aleung/5194777 – aleung
Chúng tôi đã sử dụng phiên bản @aleung được sửa đổi trong gần một năm nay mà không gặp sự cố Các sửa đổi để xử lý 'maven-metadata.xml' và '.sha' và các tệp '.md5' có thể tìm thấy trong gist được chia nhỏ: https://gist.github.com/jakub-bochenski/7802ee7f44b8e3b99bdd69b2ab150e6c –
- 1. Tải toàn bộ thư mục qua PHP FTP
- 2. Triển khai nhiều JAR của bên thứ ba đến toàn cầu (nội bộ) Maven nexus
- 3. Cách tải plugin maven lên kho lưu trữ Nexus?
- 4. Ivy qua Nexus proxy
- 5. jpegtran toàn bộ thư mục
- 6. Zip toàn bộ thư mục trên S3
- 7. Làm thế nào để tải xuống toàn bộ thư mục và thư mục con bằng cách sử dụng wget?
- 8. Tải lên thư mục qua thiết bị đầu cuối Mac
- 9. Cấu trúc thư mục Maven
- 10. C# Tải lên toàn bộ thư mục bằng cách sử dụng FTP
- 11. Git Bỏ qua và mục tiêu Maven
- 12. ASP.NET MVC 2 - Cách bỏ qua toàn bộ thư mục bằng cách sử dụng IgnoreRoute?
- 13. Làm thế nào để không tải xuống toàn bộ thư mục với (rùa) SVN
- 14. Maven không thể tải xuống các hiện vật từ HTTPS Nexus với xác thực bắt buộc
- 15. Máy nén YUI trên toàn bộ thư mục - os x
- 16. cách git cam kết toàn bộ thư mục?
- 17. cách xem các thay đổi trong toàn bộ thư mục/thư mục chứa nhiều tệp sass
- 18. Làm sạch các chỉ mục cũ từ Sonatype Nexus
- 19. Sử dụng triển khai mvn qua webdav: tạo thư mục
- 20. thông số cấu trúc thư mục kho lưu trữ maven
- 21. Cài đặt Maven qua SSO?
- 22. Cấu trúc thư mục Android Maven
- 23. Proxy tất cả kho lưu trữ phụ thuộc maven thông qua Nexus
- 24. biên dịch với maven và nexus bị kẹt khi tải xuống hiện vật
- 25. Git bỏ qua thư mục đã xóa cục bộ
- 26. AngularJS tải bộ điều khiển từ thư mục
- 27. Tải lại toàn bộ trang trên Đăng/Chuyển hướng/Bỏ qua kiểm soát bộ nhớ cache
- 28. Lặp qua một thư mục
- 29. Tại sao thư mục thùng rác của Nexus không bao giờ trống?
- 30. Maven: Bao gồm thư mục META-INF trong thư mục lớp học
đó sẽ là một hiện maven repo hoặc một số tập tin tùy ý? –
Để tải lên máy chủ Nexus, đây là các tệp tùy ý. Để tải xuống từ máy chủ, tôi đoán điều này sẽ đến từ kho lưu trữ của Nexus. – Peter