Gradle编译正常但图片资源异常问题咨询
Hey there, let's figure out why your PNG images aren't making it into the build while CSS files work perfectly.
Looking at your build.gradle config, the root cause is in how you've configured the resource includes. You're setting the includes property twice:
includes = ["**/*.png"] includes = ["**/*.css"]
Each time you use the assignment operator =, you're replacing the entire list of included files instead of adding to it. That means only the last pattern (**/*.css) is actually being applied—so your PNGs are getting ignored entirely.
Fixes you can apply
There are two straightforward ways to fix this:
Combine both patterns into a single
includeslist
Update yoursourceSetsblock to include both file types in one line:sourceSets { main { resources { srcDirs = ["src/main/java"] includes = ["**/*.png", "**/*.css"] } } }Use
include(singular) multiple times
If you prefer more readable, line-by-line configuration, use the singularincludemethod to add each file type separately:sourceSets { main { resources { srcDirs = ["src/main/java"] include "**/*.png" include "**/*.css" } } }
After making either change, run gradle clean build to clear any old build artifacts and ensure the new resources are properly packaged with your compiled code. That should get your PNGs working alongside the CSS files!
内容的提问来源于stack exchange,提问作者Ceylon Boy

