问题
I am using Micronaut framework for a project and Micronaut CLI generates project with com.github.johnrengelman.shadow
gradle plugin which works fine when I run the jar using-
$ java -Dmicronaut.environments=E1 -jar build/appBundle/app.jar
build.gradle-
plugins {
id "com.github.johnrengelman.shadow" version "5.0.0"
}
...
shadowJar {
mergeServiceFiles()
}
The issue is that com.github.johnrengelman.shadow
plugin is not working with Jenkins for some reason and I am suspecting that it's not available in our corporate repo(and can't be added). While I am able to create an executable fat-jar using jar
task of java
plugin, it fails with following error-
$ java -Dmicronaut.environments=E1 -jar build/appBundle/app.jar
16:12:22.662 [main] INFO i.m.context.env.DefaultEnvironment - Established active environments: [E1]
16:12:22.863 [main] INFO io.micronaut.runtime.Micronaut - No embedded container found. Running as CLI application
build.gradle-
plugins {
id "java"
}
...
jar {
manifest {
attributes "Main-Class": "axp.payments.pci.dss.PaymentsPciDssDispatcher"
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
Primary ask is why wouldn't com.github.johnrengelman.shadow
plugin work with a corporate repository?
回答1:
Solved
The issue was that plugin{...} block doesn't access private/corporate repo.
Solved it by reverting plugin definition from plugins{...}
to older way of definition which is apply plugin...
Added older way of applying plugin (which is the only way to make it work with private repo)-
apply plugin: "com.github.johnrengelman.shadow"
Removed (doesn't access private/corporate repo)-
plugins {
id "com.github.johnrengelman.shadow"
}
For more info, checkout first comment in this SO question.
回答2:
There is one way who you can workaround that irritating situation.
You can download the shadow jar plugin source code from GitHub and add into to your Micronaut application repository in the <project-root-folder>/buildSrc
directory.
You can follow this guide for how to create a custom plugin https://guides.gradle.org/writing-gradle-plugins
With that approach the shadow plugin is in your codebase and you can use it without downloading it.
One last thought. A company that does not allow you to proxy open source software like this plugin in the corporate repository is hindering you in your work. You might wanna talk to your manager.
My described workaround is horrible since
- you have to upgrade the plugin based on source code
- it will most likely be outdated very soon
- it is simply not the way to do it
Good luck. Hope this helps.
来源:https://stackoverflow.com/questions/58720932/micronaut-shadow-fat-jar-plugin-not-working-with-corporate-repo