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

Spring classpath filtering via Gradle plugin #34

Closed
sdeleuze opened this issue Jun 7, 2018 · 9 comments
Closed

Spring classpath filtering via Gradle plugin #34

sdeleuze opened this issue Jun 7, 2018 · 9 comments
Assignees
Labels
status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement

Comments

@sdeleuze
Copy link
Collaborator

sdeleuze commented Jun 7, 2018

We should be able to do that with something like:

compile("org.springframework:spring-web") {
		registerTransform {
			from.attribute(filtered, false).attribute(artifactType, "jar")
			to.attribute(filtered, true).attribute(artifactType, "jar")
			artifactTransform(FilterClasses::class.java)
		}
	}
}

// Same for spring-webflux, spring-context, spring-data-commons, etc.
class SpringFuWebFilter : ArtifactTransform() {
	
	private val classesToFilter = arrayOf(
			"org/springframework/remoting/**",
			"org/springframework/web/accept/**",
			"org/springframework/web/bind/**",
			"org/springframework/web/client/**",
			"org/springframework/web/context/**",
			"org/springframework/web/filter/**",
			"org/springframework/web/jsf/**",
			"org/springframework/web/method/**",
			"org/springframework/web/multipart/**",
		)
)

	override fun transform(input: File): List<File> {
		return if (...) listOf(input) else emptyList()
	}
}

See also https://github.com/gradle/gradle/blob/master/buildSrc/subprojects/packaging/src/main/kotlin/org/gradle/gradlebuild/packaging/MinifyPlugin.kt

@sdeleuze sdeleuze added this to the 1.0.0.M1 milestone Jun 7, 2018
@sdeleuze sdeleuze self-assigned this Jun 7, 2018
@sdeleuze sdeleuze changed the title Support JAR minification via Spring package filtering Support JAR minimization via Spring packages filtering Jun 7, 2018
sdeleuze added a commit that referenced this issue Jun 7, 2018
@sdeleuze sdeleuze changed the title Support JAR minimization via Spring packages filtering Spring packages filtering for minimal classpath and minimized JAR Jun 7, 2018
@sdeleuze
Copy link
Collaborator Author

sdeleuze added a commit that referenced this issue Jun 14, 2018
This example is used to experiment about classpath filtering
and benchmarking.

Issue gh-34
@sdeleuze
Copy link
Collaborator Author

There is now a minimal sample with class filtering and some preliminary benchmarks.

sdeleuze added a commit that referenced this issue Jun 15, 2018
@sdeleuze
Copy link
Collaborator Author

For the record, the former configuration I was using with ShadowJar:

tasks.withType<ShadowJar> {
	exclude("org/springframework/cglib/**",
			"org/springframework/beans/factory/groovy/**",
			"org/springframework/beans/factory/xml/**",
			"org/springframework/cache",
			"org/springframework/context/annotation",
			"org/springframework/context/support/*Xml*.class",
			"org/springframework/context/support/*Groovy*.class",
			"org/springframework/ejb/**",
			"org/springframework/instrument/classloading/**",
			"org/springframework/jmx/**",
			"org/springframework/jndi/**",
			"org/springframework/remoting/**",
			"org/springframework/scheduling/**",
			"org/springframework/scripting/**",
			"org/springframework/web/accept/**",
			"org/springframework/web/bind/**",
			"org/springframework/web/client/**",
			"org/springframework/web/context/**",
			"org/springframework/web/filter/**",
			"org/springframework/web/jsf/**",
			"org/springframework/web/method/**",
			"org/springframework/web/multipart/**",
			"org/springframework/util/xml/**")
}

@sdeleuze sdeleuze modified the milestones: 0.0.1, 0.0.2 Sep 6, 2018
@sdeleuze sdeleuze changed the title Spring packages filtering for minimal classpath and minimized JAR Spring classpath filtering via Gradle plugin Sep 10, 2018
@sdeleuze sdeleuze modified the milestones: 0.0.2, 0.0.3 Oct 1, 2018
@sdeleuze sdeleuze removed this from the 0.0.4 milestone Nov 23, 2018
@sdeleuze sdeleuze added this to the 0.0.5 milestone Dec 24, 2018
@sdeleuze
Copy link
Collaborator Author

sdeleuze commented Jan 2, 2019

This comment gives interesting insights about why it could be interesting to have a limited number of unused class when it comes to run application in the Cloud (here for Cloud Foundry but I think it could apply to other Cloud Java support).

@sdeleuze sdeleuze modified the milestones: 0.0.5, 0.0.4 Jan 10, 2019
@sdeleuze
Copy link
Collaborator Author

It seems Gradle 5.1 now provides a dedicated API: gradle/gradle@0514a4c !

@sdeleuze
Copy link
Collaborator Author

Initial plugin available in https://github.com/spring-projects/spring-fu/tree/gradle-plugin but I have not find yet why the artifact transformation is not invoked.

@sdeleuze sdeleuze modified the milestones: 0.0.4, 0.0.5 Jan 15, 2019
@sdeleuze sdeleuze added this to the 0.0.6 milestone Jan 15, 2019
@sdeleuze sdeleuze modified the milestones: 0.0.6, 0.0.7 Feb 1, 2019
@sdeleuze sdeleuze removed this from the 0.2 milestone May 14, 2019
@sdeleuze
Copy link
Collaborator Author

Gradle 5.5 with official support and documentation for artifact transformation has been released.

@sdeleuze
Copy link
Collaborator Author

I think GraalVM native images or Jlink are better solution to this need.

@sdeleuze sdeleuze added status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement labels Jan 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant