qaware / go-offline-maven-plugin

Maven Plugin used to download all Dependencies and Plugins required in a Maven build, so the build can be run without an internet connection afterwards.
Apache License 2.0
162 stars 15 forks source link

Cannot specifiy type of dynamic dependency #22

Closed joehni closed 4 years ago

joehni commented 4 years ago

We have themes in ZIP files that are unpacked by the dependency:unpack goal and specified with the artifactItems configuration. Therefore these artifacts will by downloaded dynamically during the build.

However, it is not possible to specify the type of a dynamic dependency:

<dynamicDependency>
    <groupId>com.company</groupId>
    <artifactId>site-themes</artifactId>
    <version>1.0</version>
    <classifier>blue</classifier>
    <type>zip</type>
    <repositoryType>MAIN</repositoryType>
</dynamicDependency>

It complains about the type element and without it tries to download a jar file.

Theoderich commented 4 years ago

You are right, the type specifier is indeed missing from the dynamicDependency configuration element. I will add it as soon as I have time

Theoderich commented 4 years ago

I have made the necessary changes on master. Are you able to build the plugin locally and test if it works for you?

joehni commented 4 years ago

Hi,

thanks for your fast reaction. Yes, the current master works for me, but it is not correct, because the type of a Maven artifact is not necessarily its extension. Try to address now a plugin with its correct type:

<dynamicDependency>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-verifier-plugin</artifactId>
    <version>1.1</version>
    <type>maven-plugin</type>
    <repositoryType>PLUGIN</repositoryType>
</dynamicDependency>

You will have to use the typeRegistry for this:

diff --git a/src/main/java/de/qaware/maven/plugin/offline/DependencyDownloader.java b/src/main/java/de/qaware/maven/plugin/offline/DependencyDownloader.java
index 2b218e6..f914976 100644
--- a/src/main/java/de/qaware/maven/plugin/offline/DependencyDownloader.java
+++ b/src/main/java/de/qaware/maven/plugin/offline/DependencyDownloader.java
@@ -277,7 +277,9 @@ public class DependencyDownloader {
      * @param dynamicDependency the dependency to download
      */
     public Set<ArtifactWithRepoType> resolveDynamicDependency(DynamicDependency dynamicDependency) {
-        DefaultArtifact artifact = new DefaultArtifact(dynamicDependency.getGroupId(), dynamicDependency.getArtifactId(), dynamicDependency.getClassifier(), "jar", dynamicDependency.getVersion());
+        ArtifactType artifactType = typeRegistry.get(dynamicDependency.getType());
+        String extension = artifactType!= null ? artifactType.getExtension() : dynamicDependency.getType();
+        DefaultArtifact artifact = new DefaultArtifact(dynamicDependency.getGroupId(), dynamicDependency.getArtifactId(), dynamicDependency.getClassifier(), extension, dynamicDependency.getVersion());

         CollectRequest collectRequest = new CollectRequest();
         collectRequest.setRoot(new Dependency(artifact, null));
Theoderich commented 4 years ago

Right, thanks for the review :) I have fixed it on the master. I will release a new version to maven-central with the new feature now

joehni commented 4 years ago

Thanks, a new release would be great.

joehni commented 4 years ago

Hi Theoderich, do you have a time schedule for a new release?

Theoderich commented 4 years ago

The Sync with mvn-central is in progress and should be done SOON™

joehni commented 4 years ago

Thanks!