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

Change scope of Maven core artifacts to provided #4034

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ project.ext.dependencyStrings = [
MAVEN_CORE: 'org.apache.maven:maven-core:3.9.1',
MAVEN_COMPAT: 'org.apache.maven:maven-compat:3.9.1',
MAVEN_PLUGIN_ANNOTATIONS: 'org.apache.maven.plugin-tools:maven-plugin-annotations:3.8.2',
MAVEN_SHARED_UTILS: 'org.apache.maven.shared:maven-shared-utils:3.3.4',

//test
TRUTH: 'com.google.truth:truth:1.1.3',
Expand Down Expand Up @@ -338,6 +339,19 @@ subprojects {
developerConnection = 'scm:git://github.com/GoogleContainerTools/jib.git'
}
}
pom.withXml {
project.configurations.compileOnly.allDependencies.each { dep ->
// Workaround sourceProject() using compileOnly, but jib artifacts shouldn't have provided scope
if(dep.group.startsWith("org.apache.maven")) {
asNode().dependencies[0].appendNode('dependency').with {
it.appendNode('groupId', dep.group)
it.appendNode('artifactId', dep.name)
it.appendNode('version', dep.version)
it.appendNode('scope', 'provided')
}
}
}
}
}
}
}
Expand Down Expand Up @@ -368,8 +382,8 @@ subprojects {
// sourceProject(Project) accepts a project and adds it as a dependency in a special manner:
// 1. force evaluation of the project first
// 2. add the project classes as "compileOnly" and make it available to tests in "testImplementation"
// 3. add the project's depedencies as "implementation"
// 4. remove any transitive reference of any sourceProject depenency that may have appeared
// 3. add the project's dependencies as "implementation"
// 4. remove any transitive reference of any sourceProject dependency that may have appeared
// 5. add the project's classes to the final jar
// Other nice effects (vs shadowJar)
// 1. Generated poms will be correct
Expand All @@ -378,7 +392,7 @@ subprojects {
project.ext.sourceProject = { Project dependencyProject ->
// make sure those projects are evaluated first so we know their dependencies
project.evaluationDependsOn dependencyProject.path
// add the sourceProjecect dependency
// add the sourceProject dependency
def dependencyProjectClasses = dependencyProject.sourceSets.main.output
dependencies {
// add the dependencyProject classes as compileOnly, make it available to tests
Expand Down
2 changes: 1 addition & 1 deletion examples/helloworld/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jib-maven-plugin.version>3.3.2</jib-maven-plugin.version>
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
</properties>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion jib-maven-plugin-extension-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
dependencies {
api dependencyStrings.BUILD_PLAN
api dependencyStrings.EXTENSION_COMMON
api dependencyStrings.MAVEN_CORE
compileOnly dependencyStrings.MAVEN_CORE
}

jar {
Expand Down
5 changes: 3 additions & 2 deletions jib-maven-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ dependencies {

implementation dependencyStrings.MAVEN_EXTENSION

implementation dependencyStrings.MAVEN_API
implementation dependencyStrings.MAVEN_CORE
compileOnly dependencyStrings.MAVEN_API
compileOnly dependencyStrings.MAVEN_CORE
implementation dependencyStrings.MAVEN_SHARED_UTILS

// compileOnly + testImplementation equivalent to "provided"
compileOnly dependencyStrings.MAVEN_PLUGIN_ANNOTATIONS
Expand Down