我是Gradle的新手,所以这可能只是对潜在机制的误解。我正在尝试将Maven构建转换为Gradle。我得到它来构建,唯一缺少的是替换某些资源文件中的标记/变量。
Maven代码如下所示:
<build>
<finalName>${project.artifactId}</finalName>
<resources>
<resource>
<directory>${basedir}/src/main/res</directory>
<targetPath>${project.build.directory}/res</targetPath>
<filtering>true</filtering>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
<include>**/*.cfg</include>
</includes>
</resource>
<resource>
<directory>${basedir}/src/main/res</directory>
<targetPath>${project.build.directory}/res</targetPath>
<filtering>false</filtering>
<excludes>
<exclude>**/*.psd</exclude>
<exclude>**/*.xml</exclude>
<exclude>**/*.properties</exclude>
<exclude>**/*.cfg</exclude>
</excludes>
</resource>
<resource>
<directory>${basedir}/src/main/assets</directory>
<targetPath>${project.build.directory}/assets</targetPath>
<filtering>true</filtering>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
<include>**/*.cfg</include>
</includes>
</resource>
<resource>
<directory>${basedir}/src/main/assets</directory>
<targetPath>${project.build.directory}/assets</targetPath>
<filtering>false</filtering>
<excludes>
<exclude>**/*.psd</exclude>
<exclude>**/*.xml</exclude>
<exclude>**/*.properties</exclude>
<exclude>**/*.cfg</exclude>
</excludes>
</resource>
</resources>
<!-- PLUGINS -->
</build>
现在我想在Gradle中拥有相同的东西。我不需要不同的变体和口味。此外,我对默认文件夹结构感到满意,并且除非确实需要,否则不想重新定义它。我能想到的只有
task copyFiles(type: Copy) {
from('src/main/res/') {
exclude '**/*.psd'
exclude '**/*.xml'
exclude '**/*.properties'
exclude '**/*.cfg'
}
from('src/main/res/') {
include '**/*.xml'
include '**/*.properties'
include '**/*.cfg'
expand(project.properties)
}
from('src/main/assets/') {
exclude '**/*.psd'
exclude '**/*.xml'
exclude '**/*.properties'
exclude '**/*.cfg'
}
from('src/main/assets/') {
include '**/*.xml'
include '**/*.properties'
include '**/*.cfg'
expand(project.properties)
}
into { getDestinationDir() }
}
preBuild.dependsOn copyFiles
属性在gradle.properties中定义。我认为getDestinationDir()会将它复制到默认目录(放置它而不会弄乱复制任务),但它会导致StackOverflow。
我想替换令牌的文件示例:
<?xml version="1.0" encoding="utf-8"?>
<wearableApp package="${myproject.package}">
<versionCode>7</versionCode>
<versionName>${project.version}</versionName>
<rawPathResId>myproject_wear</rawPathResId>
</wearableApp>
和
mode.release=${moderelease}
common.version=${projectversion}
我尝试了大约8个小时的工作,但现在我不知道该怎么办,所以任何帮助都会受到赞赏。