2010-07-13 4 views
7

Nexus 리포지토리 서버에서/Nexus 리포지토리 서버로/디렉토리 내의 모든 하위 디렉토리를 업로드/다운로드 할 수 있습니까?Maven을 통해 전체 디렉토리를 Nexus로 업로드/다운로드

+0

에 정교

가 기존 될 것 메이븐 레포 또는 일부 임의의 파일? –

+0

Nexus 서버에 업로드하는 경우 임의 파일 용입니다. 서버에서 다운로드 할 경우 Nexus 저장소에서 가져온 것 같습니다. – Peter

답변

2

언제든지 디렉토리를 압축하여 zip 파일로 제공 할 수 있습니다. 이 폴더의 사용자는 Nexus에서 다운로드하여 dependency : unpack을 사용하여 압축을 풀 수 있습니다.

+0

예, 이것은 확실히 한 가지 방법이지만 요구 사항을 완전히 충족 시키지는 못합니다. 의견을 주셔서 감사합니다 =) – Peter

+0

글쎄, 당신은 내 대답 속도로 내게 감사 할 수 있습니다 :) – rperez

4

실제로 파일 계층 구조를 배포하려는 경우 GMaven (그루비가 maven에 임베드 됨)을 사용하여 솔루션을 해킹했습니다.

아래의 정보를 사용하고 몇 가지 속성을 입력하고 mvn install을 누르십시오. 폴더가 크롤링되고 그 안에있는 모든 파일이 상대 경로에서 가져온 artifactId를 사용하여 배포됩니다. 예 :

은 artifactId를 def-ghi-jkl 및 포장 mno있을 것입니다 기본 폴더

c:\a\b\c 

에게 파일

c:\a\b\c\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

+0

흥미 롭다, 나는 그것을 들여다 볼 것입니다. 감사! – Peter

+1

도움이 되었습니까? 로컬 저장소 폴더 구조에 맞게 수정했습니다. https://gist.github.com/aleung/5194777 – aleung

+1

우리는 문제없이 거의 1 년 동안 @aleung 스크립트의 수정 된 버전을 사용했습니다. 'maven-metadata.xml'및 '.sha' 및 '.md5'파일은 갈래 요지에서 찾을 수 있습니다. https://gist.github.com/jakub-bochenski/7802ee7f44b8e3b99bdd69b2ab150e6c –

관련 문제