2016-08-08 2 views

答えて

7

あなたは、具体的ネクサスをターゲットにする場合、あなたがアップロードを実行するためにtheir REST APIを使用する方が簡単かもしれません:

ここではカールを使用して、いくつかの例です。

アーティファクトをアップロードし、POMファイル生成
  1. :あなたは、Javaプログラムで

    curl -v -F r=releases -F hasPom=true -F e=jar -F [email protected] -F [email protected] -u admin:admin123 http://localhost:8081/nexus/service/local/artifact/maven/content 
    

:POMファイルとアーティファクトをアップロードする

curl -v -F r=releases -F hasPom=false -F e=jar -F g=com.test -F a=project -F v=1.0 -F p=jar -F [email protected] -u admin:admin123 http://localhost:8081/nexus/service/local/artifact/maven/content 
  • HttpURLConnectionを使用してPOST呼び出しを行います(example of that hereauthentication heredocumentation of cURL here)。基本的には、POSTパラメータに、あなたは(あなたがそれでPOMをアップロードしている場合やfalser=releaseshasPom=trueを持っている必要があり、アーティファクトの延長egavp座標の(のgroupId、たartifactId 、バージョンとパッケージ)、最後にfileを展開します。

    スナップショットbecause it is explicitely disabledをアップロードすることはできません。


    あなたはどんなアーティファクトのために、そして何でもリモートリポジトリのために働くだろう、より汎用的なソリューションを、(たとえローカル1)したい場合は、直接のMavenでのシーンの下で使用されているオードのAPIを使用することができます3.1以上。チームは、DeployArtifactsサンプルにそのようなタスクの例を示します。

    プロジェクトにオードの依存関係を追加します。

    <dependencies> 
        <dependency> 
         <groupId>org.eclipse.aether</groupId> 
         <artifactId>aether-impl</artifactId> 
         <version>${aetherVersion}</version> 
        </dependency> 
        <dependency> 
         <groupId>org.eclipse.aether</groupId> 
         <artifactId>aether-connector-basic</artifactId> 
         <version>${aetherVersion}</version> 
        </dependency> 
        <dependency> 
         <groupId>org.eclipse.aether</groupId> 
         <artifactId>aether-transport-file</artifactId> 
         <version>${aetherVersion}</version> 
        </dependency> 
        <dependency> 
         <groupId>org.eclipse.aether</groupId> 
         <artifactId>aether-transport-http</artifactId> 
         <version>${aetherVersion}</version> 
        </dependency> 
        <dependency> 
         <groupId>org.apache.maven</groupId> 
         <artifactId>maven-aether-provider</artifactId> 
         <version>${mavenVersion}</version> 
        </dependency> 
    </dependencies> 
    <properties> 
        <aetherVersion>1.1.0</aetherVersion> 
        <mavenVersion>3.3.9</mavenVersion> 
    </properties> 
    

    そしてあなたがアーティファクトをデプロイするには、次のコードを持つことができます。

    public static void main(String[] args) throws DeploymentException { 
        RepositorySystem system = newRepositorySystem(); 
        RepositorySystemSession session = newSession(system); 
    
        Artifact artifact = new DefaultArtifact("groupId", "artifactId", "classifier", "extension", "version"); 
        artifact = artifact.setFile(new File("/path/to/file")); 
    
        // add authentication to connect to remove repository 
        Authentication authentication = new AuthenticationBuilder().addUsername("username").addPassword("password").build(); 
    
        // creates a remote repo at the given URL to deploy to 
        RemoteRepository distRepo = new RemoteRepository.Builder("id", "default", "url").setAuthentication(authentication).build(); 
    
        DeployRequest deployRequest = new DeployRequest(); 
        deployRequest.addArtifact(artifact); 
        deployRequest.setRepository(distRepo); 
    
        system.deploy(session, deployRequest); 
    } 
    
    private static RepositorySystem newRepositorySystem() { 
        DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator(); 
        locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class); 
        locator.addService(TransporterFactory.class, FileTransporterFactory.class); 
        locator.addService(TransporterFactory.class, HttpTransporterFactory.class); 
        return locator.getService(RepositorySystem.class); 
    } 
    
    private static RepositorySystemSession newSession(RepositorySystem system) { 
        DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); 
        LocalRepository localRepo = new LocalRepository("target/local-repo"); 
        session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo)); 
        return session; 
    } 
    

    このコードは、与えられた座標を有する単一のアーティファクトを展開します( groupIdを構成リモートリポジトリに、たartifactId、種類、分類器及びバージョン):

    • Iあなたは空のStringを渡して空白のままにすることができます。たとえば、クラシファイアなしで展開する場合は、""をクラシファイアとして使用できます。
    • 展開するファイルは、Artifactの方法setFileで設定します。
    • リモートリポジトリは、ID、レイアウト、およびURLで構成されています。"default"レイアウトは、Maven 2リポジトリで使用されるレイアウトです(Maven 1では"legacy"レイアウトとは異なります)。 URLはdeploy-file goalの内部で使用するURLと同じなので、file:///C:/m2-repoまたはscp://host.com/path/to/repoです。
    • Authenticationを作成して、リモートリポジトリに接続することができます(スニペットに示されています)。

    あなたがそれを添付アーティファクトを展開したい場合は、POMファイルと同様に、あなたがSubArtifactを作成することができます。これは、上記のように構成されたアーティファクトに、分類器なしで、POMアーティファクトを添付します

    Artifact pomArtifact = new SubArtifact(artifact, "", "pom"); 
    pomArtifact = pomArtifact.setFile(new File("pom.xml")); 
    

    。次に、主なものと同様に展開要求に追加することができます。

    deployRequest.addArtifact(artifact).addArtifact(pomArtifact); 
    

    これらの両方が展開されます。

  • 3

    Eclipse Aether APIを使用して、プログラムでJavaでプログラムを実行できます。詳細については、私のMaven Repository Toolsの出典を確認してください。事実、すべての成果物がすでにMavenリポジトリ形式のローカルフォルダにある場合は、必要に応じてすぐにそのまま使用することができます。

    具体的に展開関連コードが

    https://github.com/simpligility/maven-repository-tools/blob/master/maven-repository-provisioner/src/main/java/com/simpligility/maven/provisioner/MavenRepositoryDeployer.java

    であります
    関連する問題