Skip to content

Commit

Permalink
Fix Gradle deprecations (#3892)
Browse files Browse the repository at this point in the history
Co-authored-by: Clayton Walker <[email protected]>
Co-authored-by: Emily Wang <[email protected]>
  • Loading branch information
3 people authored Jul 11, 2023
1 parent 255534f commit 201c810
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 64 deletions.
29 changes: 11 additions & 18 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ subprojects {
/* CHECKSTYLE */

/* TEST CONFIG */
tasks.withType(Test) {
reports.html.setDestination file("${reporting.baseDir}/${name}")
tasks.withType(Test).configureEach {
reports.html.outputLocation = file("${reporting.baseDir}/${name}")
}

test {
Expand All @@ -180,7 +180,7 @@ subprojects {
// testCompile project(path:':project-name', configuration:'tests')
task testJar(type: Jar) {
from sourceSets.test.output.classesDirs
classifier = 'tests'
archiveClassifier = 'tests'
}
// to import resources do: sourceSets.test.resources.srcDirs project(':project-name').sourceSets.test.resources

Expand All @@ -198,6 +198,8 @@ subprojects {
integrationTest {
java.srcDir file('src/integration-test/java')
resources.srcDir file('src/integration-test/resources')
compileClasspath += sourceSets.main.output + sourceSets.test.output
runtimeClasspath += sourceSets.main.output + sourceSets.test.output
}
}

Expand All @@ -207,15 +209,6 @@ subprojects {
integrationTestRuntime.extendsFrom testRuntime
}

dependencies {
integrationTestImplementation sourceSets.main.output
integrationTestImplementation sourceSets.test.output
integrationTestImplementation configurations.compile
integrationTestImplementation configurations.testImplementation
integrationTestImplementation configurations.runtime
integrationTestImplementation configurations.testRuntime
}

// Integration tests must be run explicitly
task integrationTest(type: Test) {
testClassesDirs = sourceSets.integrationTest.output.classesDirs
Expand All @@ -226,7 +219,7 @@ subprojects {

task integrationTestJar(type: Jar) {
from sourceSets.integrationTest.output.classesDirs
classifier = 'integration-tests'
archiveClassifier = 'integration-tests'
}

configurations {
Expand Down Expand Up @@ -280,12 +273,12 @@ subprojects {
apply plugin: 'maven-publish'
task sourceJar(type: Jar) {
from sourceSets.main.allJava
classifier 'sources'
archiveClassifier = 'sources'
}

task javadocJar(type: Jar, dependsOn: javadoc) {
from javadoc.destinationDir
classifier 'javadoc'
archiveClassifier = 'javadoc'
}

publishing {
Expand Down Expand Up @@ -420,12 +413,12 @@ subprojects {
/* TEST COVERAGE */
jacocoTestReport {
reports {
xml.enabled true
html.enabled false
xml.required = true
html.required = false
}
}
/* TEST COVERAGE */

/* INCLUDED PROJECT DEPENDENCY HELPER */

/* LOCAL DEVELOPMENT HELPER TASKS */
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
org.gradle.jvmargs=-Xmx1024m
org.gradle.caching=true
org.gradle.parallel=true
2 changes: 1 addition & 1 deletion jib-cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ext {
// use `installDist` or `distZip` to create an installable application
application {
applicationName = 'jib'
mainClassName = cliMainClass
mainClass = cliMainClass
}

sourceSets.main.java.srcDirs += ["${buildDir}/generated-src"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@
import org.gradle.api.artifacts.component.ProjectComponentIdentifier;
import org.gradle.api.file.FileCollection;
import org.gradle.api.logging.Logger;
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.plugins.WarPlugin;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.jvm.tasks.Jar;

Expand Down Expand Up @@ -413,9 +414,9 @@ static FileCollection getInputFiles(
dependencyFileCollections.add(project.getConfigurations().getByName(configurationName));
// Output directories (classes and resources) from main SourceSet are added
// so that BuildTarTask picks up changes in these and do not skip task
JavaPluginConvention javaPluginConvention =
project.getConvention().getPlugin(JavaPluginConvention.class);
SourceSet mainSourceSet = javaPluginConvention.getSourceSets().getByName(MAIN_SOURCE_SET_NAME);
SourceSetContainer sourceSetContainer =
project.getExtensions().getByType(SourceSetContainer.class);
SourceSet mainSourceSet = sourceSetContainer.getByName(MAIN_SOURCE_SET_NAME);
dependencyFileCollections.add(mainSourceSet.getOutput());

extraDirectories.stream()
Expand All @@ -440,10 +441,10 @@ public String getVersion() {
@Override
public int getMajorJavaVersion() {
JavaVersion version = JavaVersion.current();
JavaPluginConvention javaPluginConvention =
project.getConvention().findPlugin(JavaPluginConvention.class);
if (javaPluginConvention != null) {
version = javaPluginConvention.getTargetCompatibility();
JavaPluginExtension javaPluginExtension =
project.getExtensions().findByType(JavaPluginExtension.class);
if (javaPluginExtension != null) {
version = javaPluginExtension.getTargetCompatibility();
}
return Integer.valueOf(version.getMajorVersion());
}
Expand Down Expand Up @@ -544,8 +545,8 @@ private JibGradlePluginExtension<?> findConfiguredExtension(
}

private SourceSet getMainSourceSet() {
JavaPluginConvention javaPluginConvention =
project.getConvention().getPlugin(JavaPluginConvention.class);
return javaPluginConvention.getSourceSets().getByName(MAIN_SOURCE_SET_NAME);
SourceSetContainer sourceSetContainer =
project.getExtensions().getByType(SourceSetContainer.class);
return sourceSetContainer.getByName(MAIN_SOURCE_SET_NAME);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.TaskContainer;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.api.tasks.bundling.Jar;
Expand Down Expand Up @@ -184,9 +184,8 @@ public void apply(Project project) {

SourceSet mainSourceSet =
projectAfterEvaluation
.getConvention()
.getPlugin(JavaPluginConvention.class)
.getSourceSets()
.getExtensions()
.getByType(SourceSetContainer.class)
.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
jibDependencies.add(mainSourceSet.getRuntimeClasspath());
jibDependencies.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.api.artifacts.PublishArtifact;
import org.gradle.api.initialization.Settings;
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.TaskAction;

/**
Expand Down Expand Up @@ -162,11 +162,10 @@ private void addProjectFiles(Project project) {
addGradleFiles(project);

// Add sources + resources
JavaPluginConvention javaConvention =
project.getConvention().findPlugin(JavaPluginConvention.class);
if (javaConvention != null) {
SourceSet mainSourceSet =
javaConvention.getSourceSets().findByName(SourceSet.MAIN_SOURCE_SET_NAME);
SourceSetContainer sourceSetContainer =
project.getExtensions().findByType(SourceSetContainer.class);
if (sourceSetContainer != null) {
SourceSet mainSourceSet = sourceSetContainer.findByName(SourceSet.MAIN_SOURCE_SET_NAME);
if (mainSourceSet != null) {
mainSourceSet
.getAllSource()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
import org.gradle.api.java.archives.internal.DefaultManifest;
import org.gradle.api.logging.Logger;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.bundling.War;
import org.gradle.jvm.tasks.Jar;
Expand Down Expand Up @@ -148,7 +148,7 @@ public void setUp() throws URISyntaxException, IOException {

DependencyHandler dependencies = project.getDependencies();
dependencies.add(
"compile",
"implementation",
project.files(
"dependencies/library.jarC.jar",
"dependencies/libraryB.jar",
Expand Down Expand Up @@ -258,16 +258,15 @@ public void testConvertPermissionsMap() {

@Test
public void testGetMajorJavaVersion() {
JavaPluginConvention convention =
project.getConvention().findPlugin(JavaPluginConvention.class);
JavaPluginExtension extension = project.getExtensions().findByType(JavaPluginExtension.class);

convention.setTargetCompatibility(JavaVersion.VERSION_1_3);
extension.setTargetCompatibility(JavaVersion.VERSION_1_3);
assertThat(gradleProjectProperties.getMajorJavaVersion()).isEqualTo(3);

convention.setTargetCompatibility(JavaVersion.VERSION_11);
extension.setTargetCompatibility(JavaVersion.VERSION_11);
assertThat(gradleProjectProperties.getMajorJavaVersion()).isEqualTo(11);

convention.setTargetCompatibility(JavaVersion.VERSION_1_9);
extension.setTargetCompatibility(JavaVersion.VERSION_1_9);
assertThat(gradleProjectProperties.getMajorJavaVersion()).isEqualTo(9);
}

Expand Down

0 comments on commit 201c810

Please sign in to comment.