Tôi có một số hiện vật từ cùng một nhómId (org.webjars
) và tôi cần phải giải nén chúng, sau đó sao chép tất cả các tệp js chứa vào cùng một thư mục.Maven: Làm cách nào để giải nén các tệp chính xác khỏi các tạo phẩm trong cùng một thư mục đầu ra?
Các hiện vật tài liệu lưu trữ có một hệ thống phân cấp (nén như một jar) như sau:
artifact1
- resources
- webjars
- ...
- sample-1.js
- sample-2.js
tôi cần ở cuối mỗi js tập tin được sao chép vào cùng thư mục mà không cần hệ thống cấp bậc của họ, như sau:
outputDirectory
- sample-1.js
- sample-2.js
- ...
- sample-n.js
kết quả tôi có thể đạt được là một sau:
outputDirectory
- artifact-1
- resources
- webjars
- ...
- sample-1.js
- sample-2.js
- ...
- artifact-m
- resources
- webjars
- ...
- sample-n.js
Đối mục đích này, tôi đã sử dụng 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ó một lựa chọn huyền diệu của plugin này để làm điều này, hay tôi nên cần plugin khác để hoàn thành công việc?
EDIT: Đây là giải pháp cuối cùng tôi đã sử dụng:
<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 năm sau và câu trả lời của bạn vẫn hữu ích !! –
2 năm sau và câu trả lời của bạn vẫn hữu ích !! –
Bạn có thể thay đổi giai đoạn thực hiện của plugin antrun để chuẩn bị gói. Sau đó, bạn không phải tái tạo lại cái bình. – David