001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.maven.resolver.examples; 020 021import java.io.File; 022 023import org.apache.maven.resolver.examples.util.Booter; 024import org.eclipse.aether.RepositorySystem; 025import org.eclipse.aether.RepositorySystemSession.CloseableSession; 026import org.eclipse.aether.artifact.Artifact; 027import org.eclipse.aether.artifact.DefaultArtifact; 028import org.eclipse.aether.deployment.DeployRequest; 029import org.eclipse.aether.repository.RemoteRepository; 030import org.eclipse.aether.util.artifact.SubArtifact; 031 032/** 033 * Deploys a JAR and its POM to a remote repository. 034 */ 035public class DeployArtifacts { 036 037 /** 038 * Main. 039 * @param args 040 * @throws Exception 041 */ 042 public static void main(String[] args) throws Exception { 043 System.out.println("------------------------------------------------------------"); 044 System.out.println(DeployArtifacts.class.getSimpleName()); 045 046 try (RepositorySystem system = Booter.newRepositorySystem(Booter.selectFactory(args)); 047 CloseableSession session = 048 Booter.newRepositorySystemSession(system).build()) { 049 Artifact jarArtifact = 050 new DefaultArtifact("test", "org.apache.maven.aether.examples", "", "jar", "0.1-SNAPSHOT"); 051 jarArtifact = jarArtifact.setFile(new File("src/main/data/demo.jar")); 052 053 Artifact pomArtifact = new SubArtifact(jarArtifact, "", "pom"); 054 pomArtifact = pomArtifact.setFile(new File("pom.xml")); 055 056 RemoteRepository distRepo = new RemoteRepository.Builder( 057 "org.apache.maven.aether.examples", 058 "default", 059 new File("target/dist-repo").toURI().toString()) 060 .build(); 061 062 DeployRequest deployRequest = new DeployRequest(); 063 deployRequest.addArtifact(jarArtifact).addArtifact(pomArtifact); 064 deployRequest.setRepository(distRepo); 065 066 system.deploy(session, deployRequest); 067 } 068 } 069}