Failed to exclude 'javadocJar' task which is predefined in 'withJavadocJar()'

As you anyway want to control it from commandline, you could for example have some project property that you can supply using -P and depending on that property do or do not call withJavadocJar().