0

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?

thisdotnull
  • 812
  • 1
  • 7
  • 20

2 Answers2

0

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.

thisdotnull
  • 812
  • 1
  • 7
  • 20
  • I'm trying to build with gradle 5.6.3, then i using shadow 5.2.0, bug when try to build i receive the error: > Failed to apply plugin [class 'com.github.jengelman.gradle.plugins.shadow.ShadowBasePlugin'] > This version of Shadow supports Gradle 6.0+ only. Please upgrade. – Lucas Araújo Oct 10 '22 at 17:23
-1

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.

saw303
  • 8,051
  • 7
  • 50
  • 90
  • I am not sure that's the way I want to go. Got a sample project which seems to be working with shadow plugin and corp repo. Let me explore that – thisdotnull Nov 06 '19 at 17:00
  • What I would like to understand is how the embedded server bean is getting injected with shadow plugin but not otherwise? – thisdotnull Nov 06 '19 at 17:01