Write me a gradle plugin in groovy that provides a task that builds docker images. It…
- User
Write me a gradle plugin in groovy that provides a task that builds docker images. It should be able to cache the task based on the files.
- Assistant
Sure! Here's an example of a Gradle plugin written in Groovy that provides a task to build Docker images. The task caches its output based on the input files provided:
import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.tasks.Exec class DockerBuildPlugin implements Plugin<Project> { void apply(Project project) { project.task('dockerBuild', type: DockerBuildTask) { description = 'Builds Docker images' // Input and output files for task inputs.dir 'src/main/docker' outputs.file 'build/docker/image.tar' doLast { exec { // Docker build command commandLine 'docker', 'build', '-t', 'my-docker-image', 'src/main/docker' // Cache Docker image build based on input files inputs.files fileTree('src/main/docker') outputs.file 'build/docker/image.tar' } } } } } class DockerBuildTask extends Exec { DockerBuildTask() { // Sets the working directory for the task workingDir = project.projectDir } } apply plugin: DockerBuildPlugin - User
Configuration properties should be providers
- Assistant
To modify the plugin to accept configuration properties as providers instead of fixed values, you can make the following changes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.