Skip to content

Commit

Permalink
Make Maven core provided scope
Browse files Browse the repository at this point in the history
Starting with Maven 3.9.2, it has become a build warning.
It will require a release of jib-maven-plugin-extension-api, before releasing jib-maven-plugin

- Gradle publications ignores completly compileOnly dependencies, so handling of provided scope has to be done manually.
- Declare explicity dependency maven-shared-utils for org.apache.maven.shared.utils.Os (used to be transitive)
  • Loading branch information
rquinio committed Jun 3, 2023
1 parent 934814c commit 8959964
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
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

0 comments on commit 8959964

Please sign in to comment.