This message was deleted.
# community-support
s
This message was deleted.
c
mainClass
is used in generating the application scripts, not for the manifest. If your manifest requires specific entries (should it, if
application
plugin is used?) you’ll need to add those.
for
application
the
distZip
(or
distTar
) targets should be used to build the application.
🙌 1
e
Thanks @Chris Lee What does it look like in Kotlin DSL to add the maifest?
c
Copy code
manifest {
        attributes(
            "Implementation-Title" to "Gradle",
            "Implementation-Version" to archiveVersion
        )
    }
From these docs.
e
Nope, doesn't work... where does that go... what is the context?
c
tasks.named<Jar>("jar")
- manifest is configurable on there.
e
So, I cannot use
Copy code
jar {
   . . .
}
c
believe that will work, though it eagerly instantiates the task vs lazy configuration via
tasks.named
.
e
Seriously, I cannot use
Copy code
jar { ... }
IntelliJ flags that as an error.
c
tasks.jar
would be the syntax to grab the jar task.
e
I don't think we are on the same page... How do I set the Main-Class?
Copy code
tasks.named<Jar>("jar") {
    manifest {
        attributes {
            "Main-Class" to "com.forgerock.poc.loom.Application"
        }
    }
}
does not work
c
that’s the correct approach.
e
Kotlin DSL?
c
Yes, for Kotlin DSL. you may wish to remove the application plugin and use the
java-library
plugin as it doesn’t appear you are using the application aspects of that plugin.
e
So, this cannot be made to work with the Application plugin?
c
follow the example in the docs. it’s a map as a parameter (parentheses, not braces).
Copy code
tasks.named<Jar>("jar") {
    manifest {
        attributes(
            "Main-Class" to "com.forgerock.poc.loom.Application"
        )
    }
}
it perhaps will work with the application plugin, though that plugin seems unnecessary when all you need is to package a jar with a manifest entry.
e
Okay, bloody Kotlin ( ) instead of { }
That did it...
c
cool. auto-complete is your friend there.
e
I find it so frustrating moving between Groovy and Kotlin
And, it makes no sense that I cannot say
Copy code
jar {
    manifest {
        attributes(
            "Main-Class" to "com.forgerock.poc.loom.Application"
        )
    }
}
or
Copy code
Jar {
    manifest {
        attributes(
            "Main-Class" to "com.forgerock.poc.loom.Application"
        )
    }
}
My expectation is still that the
Application
plug-in should configure the
Jar
task with
Main-Class
attribute.
c
Using main-class isn’t likely going to go very far as that won’t include your dependencies. The application plug-in creates a deployable distribution including a script to set the class path and execute jar.
e
Thanks for the reminder... later I will build an assembly with all the dependencies... I am playing with a new project using Java Loom, and Gradle 8, with Kotlin DSL... and everything breaks constantly... At the moment, I cannot run the application from gradle
Copy code
./gradlew run
does not work, and I am trying to figure that out...
Thanks again for your help @Chris Lee... thanks for putting up with my frustrations...
👍 1
With this new POC project, I am trying to use idiomatic gradle, with Kotlin, and try to learn to use things right...
v
And, it makes no sense that I cannot say
jar { ... }
.
Just use
tasks.jar { ... }
. For plugins applied using the
plugins { ... }
block there are type-safe accessors generated for Kotlin DSL. This is not breaking task configuration avoidance. In Groovy DSL yes afair, but not in Kotlin DSL.
My expectation is still that the Application plug-in should configure the Jar task with Main-Class attribute.
Why? The whole sense of that plugin is, to build a proper distribution with your code, your dependencies, maybe additional files like logging configuration, and start scripts that run the application. It does neither builds a bad-practice fat jar that repackages the dependencies, nor a runnable jar with class path and main class manifest entries. If the
run
task does not work, this has absolutely nothing to do with the jars manifest entries as the
run
task added by the
application
plugin does not run it as runnable jar. It does not even build the jar iirc. If it does not work, better provide the error you get with that so we can help to fix the actual problem. ;-)