Ho diversi artefatti dallo stesso groupId (org.webjars
) e ho bisogno di decomprimerli e quindi copiare tutti i file js contenuti nella stessa directory.Maven: Come decomprimere i file precisi dagli artefatti nella stessa directory di output?
Gli archivi manufatti hanno una gerarchia (compresso come un vaso) come segue:
artifact1
- resources
- webjars
- ...
- sample-1.js
- sample-2.js
ho bisogno alla fine che ogni JS file viene copiato nella stessa directory, senza la loro gerarchia, come segue:
outputDirectory
- sample-1.js
- sample-2.js
- ...
- sample-n.js
il risultato posso raggiungere è la seguente:
outputDirectory
- artifact-1
- resources
- webjars
- ...
- sample-1.js
- sample-2.js
- ...
- artifact-m
- resources
- webjars
- ...
- sample-n.js
Per questo scopo, ho usato il maven-dependency-plugin
:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack org.webjars dependencies</id>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>org.webjars</includeGroupIds>
<includes>**/*.js</includes>
<outputDirectory>${project.build.directory}/static</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
C'è una magica possibilità di questo plugin per fare questo, o forse dovrei bisogno di un altro plugin per completare il lavoro?
EDIT: Ecco la soluzione alla fine ho usato:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>copy org.webjars dependency to jar</id>
<phase>package</phase>
<goals><goal>run</goal></goals>
<configuration>
<target>
<copy todir="${project.build.directory}/classes/static" flatten="true">
<fileset dir="${project.build.directory}/static">
<include name="**/*.js"/>
</fileset>
</copy>
</target>
</configuration>
</execution>
</executions>
</plugin>
<!-- Force the generation of the jar to be done after the javascript dependencies have been copied.
Note : This is a half solution, as the jar is generated twice: a first time before the javascript get copied, and
another one after. As a result, there is the correct jar, but after two creations... -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>Force the jar-plugin to be called after the javascripts dependencies have been copied to be embedded</id>
<phase>package</phase>
<goals><goal>jar</goal></goals>
</execution>
</executions>
</plugin>
1 anno dopo e la tua risposta è ancora utile !! –
2 anni dopo e la tua risposta è ancora utile !! –
È possibile modificare la fase di esecuzione del plug-in antrun per preparare il pacchetto. Quindi non è necessario ricreare nuovamente il barattolo. – David