Does anyone know how you could go about keeping th...
# gradle
g
Does anyone know how you could go about keeping the run task without using the application plugin and still having the hot reload? The reason why I want to get rid of the application plugin is because it has a lot of the distribution tasks and we are packaging it with the shadow plugin
n
so why get rid of it ? using application plugin and shadowJar together works fine and sets up the manifest for you.. whats so bad about that ?
i am not sure there is a
JavaExec
task available without the application plugin and you will have to deal with setting up the arguments and possibly classpath as well.. depending on the complexity of your project
g
Shadow jar has great support of application plugin and provide shadow versions of all application plugin tasks, so I see no reason to get rid of application plugin
d
Curious (for own use) which shadow jar plugin are you using ?
g
The reason why I want to get away from the application plugin is because it comes with a lot of unecessary tasks for our use case (especially the distribution plugin which is transitive). So if the only thing that we are using from the application plugin is the run task it felt a bit like bringing in a tank to deliver a small package šŸ˜›
@DALDEI I have been using both version 2.x.x of the shadow plugin (I think this is the one in the ktor documentation) and 4.x.x and I haven’t experienced any problems with either of them
but I think I got it to work with
Copy code
task run(type: JavaExec) {
    classpath = sourceSets.main.runtimeClasspath
    main = mainClassName
}
g
Shadow also uses application plugin, so you cannot get rid of it without reimplementing everything yourself. I still don't see any reason. If those tasks are really bothering you, you can disable them and use only shadow versions
Also application plugin already bundled with Gradle and uses lazy task resolution, so you pay nothing for application plugin
g
@gildor ah cool I didn’t know that. So just bringing in the shadow-plugin will give you the distTar and distZip tasks? Then I agree, it sounds more and more like there’s no real use case for it
Would be interesting to know how that works because if I run (without the application plugin)
Copy code
./gradlew build -m
:discoverMainScriptsExtensions SKIPPED
:compileKotlin SKIPPED
:compileJava SKIPPED
:processResources SKIPPED
:classes SKIPPED
:inspectClassesForKotlinIC SKIPPED
:jar SKIPPED
:assemble SKIPPED
:discoverTestScriptsExtensions SKIPPED
:compileTestKotlin SKIPPED
:compileTestJava SKIPPED
:processTestResources SKIPPED
:testClasses SKIPPED
:test SKIPPED
:check SKIPPED
:shadowJar SKIPPED
:build SKIPPED
whilest with the application plugin I see shadowDistZip and all of the distribution tasks (distZip, distTar etc)
(but with these plugins/plugin setup)
Copy code
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'java'
apply plugin: 'kotlin'

tasks.build.dependsOn tasks.shadowJar
g
Because this config builds and jar and shadowJar, which probably not what you want
g
So what I try right now is that I do this and then I have a dockerfile which pretty much does
Copy code
ADD ./build/libs/app.jar app.jar
or would I miss out on anything from the application plugin by doing this?
(I should probably also say that this does not get published as any kind of maven artifact. The end result is a versioned docker image)
g
Application plugin just allows to create jar file with correct meta to make jar executable
You apply application plugin and shadow plugin, then build shadow jar which will contain all the dependencies and correct meta-inf so jar will be executable
Task
build
already depends on
jar
task, if you don't need common (non fat) jar, just disable this task
Or just run shadowJar and only shadow jar will be created (by default it has name with version and classifier
all
, but this is configurable)
Such jar (with all dependencies and application plugin) can be executed like this:
java -jar your-app.jar
Without application plugin it will not work
g
What do you mean by that it will not work at all? Not starting at all or will the manifest file be wrong?
Copy code
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'java'
apply plugin: 'kotlin'

tasks.build.dependsOn tasks.shadowJar
def appName="app"
mainClassName="my.example.AppKt"

shadowJar {
    baseName = appName
    classifier = null
    version = null
    manifest {
        attributes 'Main-Class': mainClassName
    }
}
becuase with this I am able to do
java -jar
on the produced ā€œapp.jarā€
(just trying to undertstand btw, I realise it might be a bit frustrating with all of these stupid questions)