2010-12-22 3 views
1

Maven 어셈블리 플러그인 용 사용자 정의 형식을 만들려고합니다. Creating a Custom Build Extension for Maven 3.0Maven 3 사용자 정의 형식

확장자에 대한 나의 pom.xml 파일 :

<?xml version="1.0"?> 
<project 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" 
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>my.maven.extention</groupId> 
    <artifactId>pkg</artifactId> 
    <version>0.0.1</version> 
    <name>maven pkg archiver</name> 
    <url>http://maven.apache.org</url> 
    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 
    <dependencies> 
     <dependency> 
      <groupId>org.codehaus.plexus</groupId> 
      <artifactId>plexus-archiver</artifactId> 
      <version>1.1</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.maven</groupId> 
      <artifactId>maven-compat</artifactId> 
      <version>3.0.1</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.maven</groupId> 
      <artifactId>maven-core</artifactId> 
      <version>3.0.1</version> 
     </dependency> 
    </dependencies> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.codehaus.plexus</groupId> 
       <artifactId>plexus-component-metadata</artifactId> 
       <version>1.5.5</version> 
       <executions> 
        <execution> 
         <goals> 
          <goal>generate-metadata</goal> 
          <goal>generate-test-metadata</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

그리고 빈 클래스 : 나는 받는다는 3 확장명을 만드는 방법 지시에 따라 사용하십시오

import java.io.IOException; 

import org.codehaus.plexus.archiver.AbstractArchiver; 
import org.codehaus.plexus.archiver.Archiver; 
import org.codehaus.plexus.archiver.ArchiverException; 
import org.codehaus.plexus.component.annotations.Component; 

@Component(role = Archiver.class, hint = "pkg") 
public class PkgArchiver extends AbstractArchiver { 

    @Override 
    protected void close() throws IOException { 
     // TODO Auto-generated method stub 

    } 

    @Override 
    protected void execute() throws ArchiverException, IOException { 
     // TODO Auto-generated method stub 

    } 

    @Override 
    protected String getArchiveType() { 
     return "pkg"; 
    } 

} 

을 그리고 내 받는다는 프로젝트에 사용

<extensions> 
    <extension> 
     <groupId>my.maven.extention</groupId> 
     <artifactId>pkg</artifactId> 
     <version>0.0.1</version> 
     </extension> 
</extensions> 

mvn failed :

[오류] 목표 org.apache.maven.plugins를 실행하지 못했습니다. maven-assembly-plugin : 2.2 : 프로젝트의 어셈블리 (기본 cli) cl3 : org.apache.maven.plugins를 실행하는 동안 형식이 호환되지 않습니다. : maven-assembly-plugin : 2.2 : 어셈블리 : my.maven.extention.pkg.PkgArchiver는 org.codehaus.plexus.archiver.Archiver로 캐스트 할 수 없습니다.

나는 과소 평가하지 않습니다. AbstractArchiver는 org.codehaus.plexus.archiver.Archiver를 구현하고 내 클래스는이 추상 클래스를 확장하기 때문입니다. 내 제안 : 다른 플러그인에 대해 다른 클래스 로더를 사용합니다. 그것은 메이븐에 대한 첫 번째 플러그인이고 나는 그것을 고칠 수있는 방법을 이해하지 않습니다.

미리 감사드립니다.

답변

1

답변을 찾았습니다. maven-assembly-plugin을 확장하려고 시도했지만 확장 또는 플러그인을 만들지 않아도되지만이 플러그인의 종속성에 내 jar 파일을 추가하십시오. 나는 간단한 받는다는 프로젝트를 생성했습니다

, pom.xml :

<?xml version="1.0"?> 
<project 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" 
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>my.maven.extention</groupId> 
    <artifactId>pkg</artifactId> 
    <version>0.0.1</version> 
    <name>maven pkg archiver</name> 
    <url>http://maven.apache.org</url> 
    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 
    <dependencies> 
     <dependency> 
      <groupId>org.codehaus.plexus</groupId> 
      <artifactId>plexus-archiver</artifactId> 
      <version>1.1</version> 
     </dependency> 
    </dependencies> 
</project> 

및 추가 구성 요소 설명 src/main/resources/META-INF/plexus/components.xml

<component-set> 
    <components> 
     <component> 
      <role>org.codehaus.plexus.archiver.Archiver</role> 
      <role-hint>pkg</role-hint> 
      <implementation>cmy.maven.extention.pkg.PkgArchiver</implementation> 
      <instantiation-strategy>per-lookup</instantiation-strategy> 
     </component> 
    </components> 
</component-set> 

그리고 PkgArchiver class에서 말뭉치 주석을 제거합니다. 그리고이 프로젝트는 maven-assembly-plugin 의존성에서 사용하십시오.

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <version>2.2</version> 
    <configuration> 
     <descriptors> 
      <descriptor>${basedir}/src/main/assembly/assembly.xml</descriptor> 
     </descriptors> 
    </configuration> 
    <dependencies> 
     <dependency> 
      <groupId>my.maven.extention</groupId> 
      <artifactId>pkg</artifactId> 
      <version>0.0.1</version> 
     </dependency> 
    </dependencies> 
</plugin> 
0

역할 PlexusIoResourceCollection을 구현하는 세 번째 구성 요소를 추가해야합니다.

다음 설명은 나를 위해 작동하고 플러그인 종속성으로 사용하는 데 필요한 클라이언트 프로젝트에서 아카이브 (우편) 확장

<?xml version="1.0" encoding="UTF-8"?> 
<component-set> 
    <components> 

     <component> 
      <role>org.codehaus.plexus.archiver.Archiver</role> 
      <role-hint>xpi</role-hint> 
       <implementation>org.codehaus.plexus.archiver.zip.ZipArchiver</implementation> 
      <instantiation-strategy>per-lookup</instantiation-strategy> 
     </component> 

     <component> 
      <role>org.codehaus.plexus.archiver.UnArchiver</role> 
      <role-hint>xpi</role-hint> 
      <implementation>org.codehaus.plexus.archiver.zip.ZipUnArchiver</implementation> 
      <instantiation-strategy>per-lookup</instantiation-strategy> 
     </component> 

     <component> 
      <role>org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection</role> 
      <role-hint>xpi</role-hint> 
      <implementation>org.codehaus.plexus.archiver.zip.PlexusIoZipFileResourceCollection</implementation> 
      <instantiation-strategy>per-lookup</instantiation-strategy> 
     </component> 

    </components> 
</component-set> 

로 확장 XPI를 처리 할 수 ​​받는다는를 얻을 수

  <artifactId>maven-assembly-plugin</artifactId> 
      <dependencies> 
       <dependency> 
        <groupId>your.group.id</groupId> 
        <artifactId>xpi-archiver</artifactId> 
        <version>1.0.0-SNAPSHOT</version> 
       </dependency> 
      </dependencies> 

빌드 확장으로 사용하면 조사하지 않은 캐스트 문제가 발생합니다.