Q:

How to run a Gradle task with different parameters

I'd like to define a task in gradle (called gen) that runs the gradle task jar but with a fix value for baseName. I also want the original task jar to be available afterwards.
My Problem is, that I can't transfer the setting for manifest.
I tired e.g.
def mainFile = 'com.so.proj.App'
def filename = 'something'

jar {
    baseName filename
    manifest {
        attributes 'Main-Class': mainFile
    }
}

task gen (type: Jar) {
    description "Generates JAR without version number."
    doFirst {
        //archiveName = jar.baseName + "." + extension
        archiveName = filename + ".jar"
        manifest {
            attributes 'Main-Class': mainFile
        }
    }
}

I thought I'm redefining the Jar task by using other values for archiveName and manifest.
When running ./gradlew jar an executable JAR file is generated.
When running ./gradlew gen a jar file is generated. Unfortunately when trying to run the program using java -jar build/libs/something.jar I get the error message:
java -jar build/libs/something.jar
Error: Could not find or load main class com.so.proj.App

What am I doing wrong? I simply want to run the jar task with different parameters (without configuring the jar task itself, but running an alias). And what is the code doing that I wrote (I don't get an error when running the task. But what is it doing?)

A:

I don't think you need doFirst in your gen task. You need to add a with jar to include all regular jar contents, which results in:
task gen (type: Jar) {
    description "Generates JAR without version number."
    archiveName = filename + ".jar"
    manifest {attributes 'Main-Class': mainFile}
    with jar
}

