Using the ! character before the path to the file should work, in your .gitignore file
# Ignore all .jar files...
*.jar
# ...except gradle-wrapper.jar
!path/to/gradle-wrapper.jar
From https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository#%5C_ignoring:
You can negate a pattern by starting it with an exclamation point (
!
).