It's common to split example code into a separate sub-project so it doesn't get compiled into your release JAR.
See here for an example: https://github.com/gradle/gradle/tree/master/subprojects/doc...
https://docs.gradle.org/current/userguide/intro_multi_projec...