I want to build JAR with self-defined version passed via command line, such as:
When I execute gradle build task like this:
gradle build -Pversion=1.
You can pass the project version on cli with -Pversion=... as long as you don't set it in build.gradle. If you need a custom default value for when no version is passed on the cli, use gradle.properties file like so: version=...
TL;DR: Don't set the version in build.gradle file if you want to change it later on via cli.