Maven and Gradle Not To Delete target or build folder
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>Deleting all files under target, but not target itself</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
<configuration>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
<filesets>
<fileset>
<directory>target/</directory>
<followSymlinks>false</followSymlinks>
<includes>
<include>**/*</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
</plugins>
</build>
tasks.named<Delete>("clean") {
// 既定(buildDir自体)の削除対象を空に
setDelete(emptyList<Any>())
doFirst {
val buildDirFile = layout.buildDirectory.get().asFile
val children = buildDirFile.listFiles()?.toList() ?: emptyList()
setDelete(children)
}
}
This post is licensed under CC BY 4.0 by the author.