diff --git a/maven-plugins/helidon-archetype-maven-plugin/pom.xml b/maven-plugins/helidon-archetype-maven-plugin/pom.xml
index 2d437cc80..c8238074f 100644
--- a/maven-plugins/helidon-archetype-maven-plugin/pom.xml
+++ b/maven-plugins/helidon-archetype-maven-plugin/pom.xml
@@ -94,6 +94,7 @@
org.apache.maven
maven-archiver
+
org.codehaus.plexus
plexus-archiver
diff --git a/maven-plugins/helidon-archetype-maven-plugin/src/main/java/io/helidon/build/maven/archetype/postgenerate/EngineFacade.java b/maven-plugins/helidon-archetype-maven-plugin/src/main/java/io/helidon/build/maven/archetype/postgenerate/EngineFacade.java
index 64467ee1e..661909408 100644
--- a/maven-plugins/helidon-archetype-maven-plugin/src/main/java/io/helidon/build/maven/archetype/postgenerate/EngineFacade.java
+++ b/maven-plugins/helidon-archetype-maven-plugin/src/main/java/io/helidon/build/maven/archetype/postgenerate/EngineFacade.java
@@ -39,6 +39,7 @@
import org.apache.maven.artifact.versioning.ComparableVersion;
import org.apache.maven.project.ProjectBuildingRequest;
import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.repository.RemoteRepository;
import static java.util.Collections.emptyMap;
@@ -66,21 +67,32 @@ public static void generate(ArchetypeGenerationRequest request, List dep
checkMavenVersion();
checkJavaVersion();
- Aether aether = EngineFacade.invoke(request, "getRepositorySession")
- // archetype-common >= 3.3.0
- .map(repoSession -> new Aether(repoSession, request.getRemoteArtifactRepositories()))
- // archetype-common < 3.3.0
- .orElseGet(() -> {
- ProjectBuildingRequest pbr = EngineFacade.invoke(request, "getProjectBuildingRequest")
- .orElseThrow(() -> new IllegalStateException("Unable to get project building request"));
- RepositorySystemSession repoSession = EngineFacade.invoke(pbr,
- "getRepositorySession")
- .orElseThrow(() -> new IllegalStateException("Unable to get repository system session"));
- List artifactRepos = EngineFacade.>invoke(request,
- "getRemoteArtifactRepositories")
- .orElseThrow(() -> new IllegalStateException("Unable to get artifact repositories"));
- return new Aether(repoSession, artifactRepos, true);
- });
+ // getRepositorySession only exists in archetype-common >= 3.3.0
+ RepositorySystemSession repoSession = EngineFacade.invoke(request, "getRepositorySession")
+ // getProjectBuildingRequest was removed in archetype-common == 3.3.0
+ .or(() -> EngineFacade.invoke(request, "getProjectBuildingRequest")
+ .map(ProjectBuildingRequest::getRepositorySession))
+ .orElseThrow(() -> new IllegalStateException("Unable to get repository system session"));
+
+ // getRemoteRepositories only exists in archetype-common >= 3.3.1
+ Aether aether = EngineFacade.>invoke(request, "getRemoteRepositories")
+ .map(remoteRepos -> new Aether(repoSession, remoteRepos))
+ .or(() -> EngineFacade.>invoke(request, "getRemoteArtifactRepositories")
+ .map(repos -> {
+ Object repo = repos.isEmpty() ? null : repos.get(0);
+ if (repo instanceof ArtifactRepository) {
+ // getRemoteArtifactRepositories returns List in archetype-common != 3.3.0
+ return new Aether(repoSession, asListOf(repos, ArtifactRepository.class), true);
+ } else if (repo instanceof RemoteRepository) {
+ // getRemoteArtifactRepositories returns List in archetype-common == 3.3.0
+ return new Aether(repoSession, asListOf(repos, RemoteRepository.class));
+ } else {
+ // empty repository, or unsupported repository type
+ return new Aether(repoSession, List.of());
+ }
+ }))
+ .orElseThrow(() -> new IllegalStateException("Unable to initialize aether"));
+
File localRepo = aether.repoSession().getLocalRepository().getBasedir();
// enable mvn:// URL support
@@ -167,4 +179,9 @@ private static Optional invoke(Object object, String methodName) {
throw new RuntimeException(ex);
}
}
+
+ @SuppressWarnings("unchecked")
+ private static List asListOf(List> list, Class type) {
+ return (List) list;
+ }
}