diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/JibPlugin.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/JibPlugin.java index 344a1bc09ca..c129702db1f 100644 --- a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/JibPlugin.java +++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/JibPlugin.java @@ -119,17 +119,10 @@ public void apply(Project project) { task.setDescription("Builds a container image to a tarball."); }); - tasks - .register(SKAFFOLD_FILES_TASK_V2_NAME, FilesTaskV2.class) - .configure(task -> task.setJibExtension(jibExtension)); - tasks - .register(SKAFFOLD_INIT_TASK_NAME, InitTask.class) - .configure(task -> task.setJibExtension(jibExtension)); + tasks.register(SKAFFOLD_FILES_TASK_V2_NAME, FilesTaskV2.class, jibExtension); + tasks.register(SKAFFOLD_INIT_TASK_NAME, InitTask.class, jibExtension); TaskProvider syncMapTask = - tasks.register( - SKAFFOLD_SYNC_MAP_TASK_NAME, - SyncMapTask.class, - task -> task.setJibExtension(jibExtension)); + tasks.register(SKAFFOLD_SYNC_MAP_TASK_NAME, SyncMapTask.class, jibExtension); // A check to catch older versions of Jib. This can be removed once we are certain people // are using Jib 1.3.1 or later. diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/skaffold/FilesTaskV2.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/skaffold/FilesTaskV2.java index 81a738a53ef..1fff953d4ea 100644 --- a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/skaffold/FilesTaskV2.java +++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/skaffold/FilesTaskV2.java @@ -19,7 +19,6 @@ import com.google.cloud.tools.jib.gradle.ExtraDirectoryParameters; import com.google.cloud.tools.jib.gradle.JibExtension; import com.google.cloud.tools.jib.plugins.common.SkaffoldFilesOutput; -import com.google.common.base.Preconditions; import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -30,7 +29,7 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; -import javax.annotation.Nullable; +import javax.inject.Inject; import org.gradle.api.DefaultTask; import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; @@ -52,11 +51,11 @@ public class FilesTaskV2 extends DefaultTask { private final SkaffoldFilesOutput skaffoldFilesOutput = new SkaffoldFilesOutput(); - @Nullable private JibExtension jibExtension; + private final JibExtension jibExtension; - public FilesTaskV2 setJibExtension(JibExtension jibExtension) { + @Inject + public FilesTaskV2(JibExtension jibExtension) { this.jibExtension = jibExtension; - return this; } /** @@ -66,7 +65,6 @@ public FilesTaskV2 setJibExtension(JibExtension jibExtension) { */ @TaskAction public void listFiles() throws IOException { - Preconditions.checkNotNull(jibExtension); Project project = getProject(); // If this is not the root project, add the root project's build.gradle and settings.gradle @@ -188,8 +186,6 @@ private void addProjectFiles(Project project) { * @return the set of project dependencies */ private Set findProjectDependencies(Project project) { - Preconditions.checkNotNull(jibExtension); - Set projectDependencies = new HashSet<>(); Deque projects = new ArrayDeque<>(); projects.push(project); diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/skaffold/InitTask.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/skaffold/InitTask.java index 5ccbea77a86..31bd215a457 100644 --- a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/skaffold/InitTask.java +++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/skaffold/InitTask.java @@ -18,9 +18,8 @@ import com.google.cloud.tools.jib.gradle.JibExtension; import com.google.cloud.tools.jib.plugins.common.SkaffoldInitOutput; -import com.google.common.base.Preconditions; import java.io.IOException; -import javax.annotation.Nullable; +import javax.inject.Inject; import org.gradle.api.DefaultTask; import org.gradle.api.Project; import org.gradle.api.tasks.TaskAction; @@ -32,11 +31,11 @@ */ public class InitTask extends DefaultTask { - @Nullable private JibExtension jibExtension; + private final JibExtension jibExtension; - public InitTask setJibExtension(JibExtension jibExtension) { + @Inject + public InitTask(JibExtension jibExtension) { this.jibExtension = jibExtension; - return this; } /** @@ -52,7 +51,7 @@ public void listModulesAndTargets() throws IOException { return; } SkaffoldInitOutput skaffoldInitOutput = new SkaffoldInitOutput(); - skaffoldInitOutput.setImage(Preconditions.checkNotNull(jibExtension).getTo().getImage()); + skaffoldInitOutput.setImage(jibExtension.getTo().getImage()); if (!project.equals(project.getRootProject())) { skaffoldInitOutput.setProject(project.getName()); } diff --git a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/skaffold/SyncMapTask.java b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/skaffold/SyncMapTask.java index 7d8d9e4b029..185aa87c9aa 100644 --- a/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/skaffold/SyncMapTask.java +++ b/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/skaffold/SyncMapTask.java @@ -23,8 +23,7 @@ import com.google.cloud.tools.jib.plugins.common.ContainerizingMode; import com.google.cloud.tools.jib.plugins.common.InvalidContainerizingModeException; import com.google.cloud.tools.jib.plugins.common.PluginConfigurationProcessor; -import com.google.common.base.Preconditions; -import javax.annotation.Nullable; +import javax.inject.Inject; import org.gradle.api.DefaultTask; import org.gradle.api.GradleException; import org.gradle.api.tasks.TaskAction; @@ -37,18 +36,16 @@ */ public class SyncMapTask extends DefaultTask { - @Nullable private JibExtension jibExtension; + private final JibExtension jibExtension; - public SyncMapTask setJibExtension(JibExtension jibExtension) { + @Inject + public SyncMapTask(JibExtension jibExtension) { this.jibExtension = jibExtension; - return this; } /** Task Action, lists files and container targets. */ @TaskAction public void listFilesAndTargets() { - Preconditions.checkNotNull(jibExtension); - try (TempDirectoryProvider tempDirectoryProvider = new TempDirectoryProvider()) { GradleProjectProperties projectProperties = GradleProjectProperties.getForProject(