Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project dependencies in a separate layer for WAR projects #2450

Closed
chanseokoh opened this issue May 5, 2020 · 10 comments · Fixed by #2502
Closed

Project dependencies in a separate layer for WAR projects #2450

chanseokoh opened this issue May 5, 2020 · 10 comments · Fixed by #2502

Comments

@chanseokoh
Copy link
Member

chanseokoh commented May 5, 2020

We put project dependencies into a separate layer for JAR projects (#1436 (comment) and #403 (comment)), but this isn't supported for WAR projects.


Note there are other related feature requests for generalized dependency control (such as excluding certain dependencies from a list and fine-controlled dependency layering):

#1962 (comment)
#403 (comment)
#403 (comment)
#403 (comment)
#403 (comment)
#1436 (comment)
#1852

Note we expect to support the generalized fined-grained dependency control through the Jib extension framework: #1962 (comment)

@ST-DDT
Copy link

ST-DDT commented May 13, 2020

I use jib-maven-plugin 2.2.0 and I have a separate layer for the dependencies.

    <packaging>war</packaging>
		}, {
			"created": "2020-05-13T13:36:58.743844200Z",
			"author": "Jib",
			"created_by": "jib-maven-plugin:2.2.0",
			"comment": "dependencies"
		}, {
			"created": "2020-05-13T13:36:58.743844200Z",
			"author": "Jib",
			"created_by": "jib-maven-plugin:2.2.0",
			"comment": "snapshot dependencies"
		}, {

Or I'm I mistaken?

@chanseokoh
Copy link
Member Author

I was talking about "project dependencies", i.e., JAR from a sibling module/sub-project within the same project.

@Eveneko
Copy link

Eveneko commented May 18, 2020

OK, I'll work on it. ;-)

@chanseokoh
Copy link
Member Author

chanseokoh commented May 18, 2020

@Eveneko thank you very much! If you need any help, let us know.

I think it's not difficult to implement this on Maven. For a non-WAR project, we identify project dependencies in MavenProjectProperties.classifyDependencies() and put them into the project dependency layer by calling javaContainerBuilder.addProjectDependencies(). However, for a WAR project, we go through a different execution path with JavaContainerBuilderHelper.fromExplodedWar(), and the helper method doesn't call addProjectDependencies(). I think we can match project dependencies in a WAR file by checking the filename of the dependency JARs in webInfLib (WEB-INF/lib/*.jar).

@Eveneko
Copy link

Eveneko commented May 29, 2020

@chanseokoh
Hi, I noticed that project dependencies are obtained by the following code in method createJibContainerBuilder in MavenProjectProperties.java:

session
    .getProjects()
    .stream()
    .map(MavenProject::getArtifact)
    .collect(Collectors.toSet())

I am not clear about MavenSession (try to find documents but failed )
I wonder if this is the same for war project to get project dependencies using MavenSession?

@chanseokoh
Copy link
Member Author

chanseokoh commented May 29, 2020

@Eveneko
Hi! Yeah, What happens is that, session.getProjects() gives us all the projects (including the root POM project and all sub-modules) involved in an entire Maven build session, and calling getArtifact() on each project tells us the output artifact (e.g., a JAR file) associated with the project. For example, if a multi-module setup looks like this,

my-project: getArtifact() returns a no-file Artifact for the root project
  +-- library-foo-module: getArtifact() returns "library-foo-*.jar" (basically)
  +-- library-bar-module: getArtifact() returns "library-bar-*.jar"
  `-- main-app: (getArtifact() returns "main-app-*.jar", but we won't care)

then in classifyDependencies(), it goes through all the dependencies of main-app to check whether they are either library-foo-*.jar or library-foo-*.jar; if so, they are classified as a project dependency.

So the same story still applies to the WAR case, basically. The difference, however, would be that you may need to check actual filenames in WEB-INF/lib/*.jar to determine if a JAR file there is from a sub-module.

@WuYff
Copy link
Contributor

WuYff commented May 30, 2020

Hi @chanseokoh, thank you for your guide. We created a pr and hope that you can review it. Working with @Eveneko.

@loosebazooka
Copy link
Member

Thanks @WuYff for your contribution! This is released as part of jib 2.4.0.

@chanseokoh chanseokoh added this to the v2.4.0 milestone Jun 10, 2020
@WuYff
Copy link
Contributor

WuYff commented Jun 10, 2020

Thanks @chanseokoh @loosebazooka ! :)

@chanseokoh
Copy link
Member Author

chanseokoh commented Jun 11, 2020

Note we expect to support the generalized fined-grained dependency control through the Jib extension framework: #1962 (comment)

The Jib Extension Framework is now available with the latest Jib versions. You can easily extend and tailor the Jib plugins behavior to your liking.

We've written a general-purpose layer-filter extension that enables fine-grained layer control, including deleting files and moving files into new layers.

For general information about using and writing extensions, take a look at the Jib Extensions repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants