2010-07-13 16 views
7

Bir dizinin tamamını ve tüm alt dizinleri bir Nexus havuz sunucusuna/sitesinden yüklemek/yüklemek mümkün mü?Maven aracılığıyla Nexus'a tüm dizini Yükleyin/İndirin

+0

ayrıntılarıyla

o varolan olurdu maven repo veya bazı keyfi dosyalar? –

+0

Nexus sunucusuna yüklemek için, bu keyfi dosyalar içindir. Sunucudan indirmek için, bu Nexus deposundan olacağını tahmin ediyorum. – Peter

cevap

2

Dizini her zaman ziplayabilir ve bir zip dosyası olarak gönderebilirsiniz. Bu klasörün kullanıcıları Nexus'tan indirebilir ve bağımlılığı kullanarak unzip: unpack.

+0

Evet, bu kesinlikle bunu yapmanın bir yoludur, ancak gereksinimleri tam olarak karşılamamaktadır. Giriş için teşekkürler =) – Peter

+0

iyi, bana teşekkür edebilirim cevabım :) – rperez

4

Dosya hiyerarşisini gerçekten dağıtmak istediğinizde, GMaven (maven içine gömülü groovy) kullanarak bir çözümü bir araya getirdim.

Aşağıdaki pompayı kullanın, birkaç özellik sağlayın ve mvn install'a basın. Klasör taranacak ve içindeki tüm dosyalar göreceli yoldan alınan bir artifactId kullanılarak dağıtılacaktır. Örneğin.

artifactId def-ghi-jkl ve paketleme mno olurdu taban klasörünü

c:\a\b\c 

dosyayı

c:\a\b\c\def\ghi\jkl.mno 

göz önüne alındığında, bu tabii ki başka bir şeye değiştirilebilir.

Depo bilgileri pomdan alınacaktır, bu nedenle pomda bir DistributionManagement öğesi sağlamanız gerekir. İşte

(kodun bir sürü deploy:deploy-file mojo alınır) olan:

<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> 

DÜZENLEME: Bu on my blog

+0

İlginç, Ben ona bakacağız. Teşekkürler! – Peter

+1

Yardımcı oldu! Yerel depo klasör yapısına uyacak şekilde değiştirdim. https://gist.github.com/aleung/5194777 – aleung

+1

Şu anda bir yıldan fazla bir süredir @aleung komutunun değiştirilmiş bir sürümünü kullanıyoruz 'maven-metadata.xml' ve '.sha' işlemek için değişiklikler ve '.md5' dosyaları forked gist'te bulunabilir: https://gist.github.com/jakub-bochenski/7802ee7f44b8e3b99bdd69b2ab150e6c –