Copying jars from Maven into src/main/jib?

656 views
Skip to first unread message

Sean LeBlanc

unread,
Jul 8, 2021, 6:41:21 PM7/8/21
to Jib users
Is there a recommended practice for getting things into this directory via Maven? We use elastic apm, and we tend to check the jar into this directory, but I'm wondering if there is not a better way to get that by having Gradle (or the Jib plugin) copy it there before Jib runs (and not add it to the completed Spring Boot jar)?

Chanseok Oh

unread,
Jul 9, 2021, 12:33:23 PM7/9/21
to Jib users
> getting things into this directory via Maven

You mean your build system is Gradle and you want to download some JARs from Maven Central? And currently, you are checking these JARs into the source repo (src/main/jib), which you don't like, right? I think you can always dynamically download files during compilation (or any stage of the build that you deem suitable), like this example? The directory doesn't have to be src/main/jib if you configure jib.extraDirectories, so you could copy the JAR into the Gradle build output directory (build/...).

BTW, having files under some Jib extra directories won't affect the contents of a Spring Boot fat JAR. And note that Jib doesn't use a Spring Boot JAR or require creating it. Jib doesn't even run the Spring Boot plugin.

Appu Goundan

unread,
Jul 9, 2021, 4:27:19 PM7/9/21
to Chanseok Oh, Jib users
I think that including binary jars in your build is less than optimal (also potentially less secure).

If you are using gradle, you can configure a custom configuration to reference the jar and have gradle download it for you. You can then copy it over using a custom task to a location you determine to be suitable.

```
configurations {
  extraJars
}

dependencies {
  extraJars "co.elastic.apm:apm-agent-api:1.24.0"
}

tasks.register("copyApm", Copy) {
  from(configurations.extraJars)
  into "build/somewhere"
}

// tell jib to run copyApm before the the "jib" task
tasks.jib.configure {
  dependsOn copyApm
}
```

--
You received this message because you are subscribed to the Google Groups "Jib users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jib-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jib-users/7a55e71c-cff9-48ba-bb52-29e0b6d8e236n%40googlegroups.com.

Sean LeBlanc

unread,
Jul 10, 2021, 10:42:59 PM7/10/21
to Jib users
Yes, that's exactly what I want. And I should have been more clear in my original question - I wanted to avoid having it added 2x (meaning putting it into the build and copying it from there to src/main/jib), but I see the solution from Appu achieves what I want.

Cheers!

Reply all
Reply to author
Forward
0 new messages