简体   繁体   English

如何使用 JIB package 自定义 Jar 任务?

[英]how to package a custom Jar task with JIB?

I'm using Jib to Containerize the output of some Gradle Jar tasks.我正在使用Jib来容器化一些 Gradle Jar 任务的 output。 This works fine for default Jar task.这适用于默认的 Jar 任务。 My issue is we have a custom Jar task hooked into our build process eg我的问题是我们有一个自定义的 Jar 任务挂接到我们的构建过程中,例如

tasks.register('myOtherJarTask',jar){
   //do stuff, triggered by assemble task
   // outputted to non default directory
} 

and I want the output of this to be containerized not the default Jar, The default Jar is also still valid for us for other reasons.并且我希望将其中的 output 容器化,而不是默认的 Jar,默认的 Jar 由于其他原因对我们仍然有效。 Is there a way to allow for this in JIB, from looking at the source code of the JIB plugin it seems it coded to expect the output of the Jar task .有没有一种方法可以在 JIB 中实现这一点,从查看 JIB 插件的源代码来看,它似乎编码为期望Jar 任务的 output Code from Jib plugin:来自 Jib 插件的代码:

      Jar jarTask = (Jar) project.getTasks().findByName("jar");
      Path jarPath = jarTask.getArchiveFile().get().getAsFile().toPath();
      log(LogEvent.debug("Using JAR: " + jarPath));
      javaContainerBuilder.addToClasspath(jarPath);

I also tried Copying the jar from 'myOtherJarTask' into the container using extraDirectories property and executing that way via a entrypoint but the default Jar does not contain a main class so that blocks this (myOtherJarTask has a main class).我还尝试使用 extraDirectories 属性将 jar 从“myOtherJarTask”复制到容器中,并通过入口点以这种方式执行,但默认的 Jar 不包含主 class,因此会阻止它(myOtherJarTask 有一个主类)。 restructuring the project so the defaut Jar produces my desired output is not a option.重组项目,使默认 Jar 产生我想要的 output 不是一个选项。

Maybe there is another way that is not clear to me.也许还有另一种我不清楚的方法。

Any help appreciated.任何帮助表示赞赏。

Just another thought: Have you tried adding your custom jar to the runtime classpath with jib.container.extraClasspath ?另一个想法:您是否尝试过使用jib.container.extraClasspath将自定义 jar 添加到运行时类路径?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM