Slackbot
08/29/2022, 4:48 PMVampire
08/29/2022, 5:01 PMFile type for your properties.
Use RegularFile and then link them together.
Then it should work properlyJEYALAL
08/29/2022, 6:06 PMRun with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.* Get more help at https://help.gradle.org BUILD FAILED in 568ms 1 actionable task: 1 executed
JEYALAL
08/29/2022, 6:08 PMVampire
08/29/2022, 7:38 PMJEYALAL
08/30/2022, 6:43 AMTask :addQuoteSource FAILEDFAILURE: Build failed with an exception. * What went wrong: A problem was found with the configuration of task ':addQuoteSource' (type 'AddQuoteSource'). _*- In plugin 'com.vitesco.abe.main' type 'com.vitesco.abe.gradle.tasks.AddQuoteSource' property 'inputFile' specifies file 'D:\src\demo\duqd2_1u_iab\quote-with-quotation-marks.txt' which doesn't exist.*_ Reason: An input file was expected to be present but it doesn't exist. Possible solutions: 1. Make sure the file exists before the task is called. 2. Make sure that the task which produces the file is declared as an input. _*Please refer to https://docs.gradle.org/7.4.2/userguide/validation_problems.html#input_file_does_not_exist for more details about this problem.*_ * Try:
Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.* Get more help at https://help.gradle.org BUILD FAILED in 3s 1 actionable task: 1 executed
package com.vitesco.abe.gradle.main;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.tasks.TaskProvider;
import com.vitesco.abe.gradle.tasks.AddQuotationMarks;
import com.vitesco.abe.gradle.tasks.AddQuoteSource;
/**
* A simple 'hello world' plugin.
*/
public class MainCustomGradlePlugin implements Plugin<Project>
{
@Override
public void apply(final Project project)
{
TaskProvider<AddQuotationMarks> addQuotationMarks = project.getTasks().register("addQuotationMarks", AddQuotationMarks.class);
TaskProvider<AddQuoteSource> addQuoteSource = project.getTasks().register("addQuoteSource", AddQuoteSource.class);
addQuoteSource.get().setInputFile(addQuotationMarks.get().getOutputFile());
}
}
package com.vitesco.abe.gradle.tasks;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import org.gradle.api.DefaultTask;
import org.gradle.api.file.RegularFile;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;
/**
*
*/
public class AddQuotationMarks extends DefaultTask
{
@InputFile
RegularFile inputFile = new RegularFile()
{
@Override
public File getAsFile()
{
return new File("D:\\src\\demo\\duqd2_1u_iab\\quote.txt");
}
};
@OutputFile
RegularFile outputFile = new RegularFile()
{
@Override
public File getAsFile()
{
return new File("D:\\src\\demo\\duqd2_1u_iab\\quote-with-quotation-marks.txt");
}
};
@TaskAction
void join()
{
System.out.println("Hello from AddQuotationMarks");
Path target = outputFile.getAsFile().toPath();
try (BufferedWriter writer = Files.newBufferedWriter(target, StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING))
{
writer.write("" + System.currentTimeMillis());
}
catch (IOException e)
{
e.printStackTrace();
}
}
/**
* @return the inputFile
*/
public RegularFile getInputFile()
{
return inputFile;
}
/**
* @return the outputFile
*/
public RegularFile getOutputFile()
{
return outputFile;
}
}
package com.vitesco.abe.gradle.tasks;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import org.gradle.api.DefaultTask;
import org.gradle.api.file.RegularFile;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;
/**
*
*/
public class AddQuoteSource extends DefaultTask
{
@InputFile
RegularFile inputFile = null;
@OutputFile
RegularFile outputFile = new RegularFile()
{
@Override
public File getAsFile()
{
return new File("D:\\src\\demo\\duqd2_1u_iab\\quote-with-source.txt");
}
};
@TaskAction
void join()
{
Path target = outputFile.getAsFile().toPath();
try (BufferedWriter writer = Files.newBufferedWriter(target, StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING))
{
writer.write("Final File : " + System.currentTimeMillis());
}
catch (IOException e)
{
e.printStackTrace();
}
}
/**
* @return the outputFile
*/
public RegularFile getOutputFile()
{
return outputFile;
}
/**
* @return the inputFile
*/
public RegularFile getInputFile()
{
return inputFile;
}
public void setInputFile(final RegularFile file)
{
this.inputFile = file;
}
}Vampire
08/30/2022, 7:57 AMRegularFileProperty, not RegularFile. Also, never do such own implementations but use it properly like documented.
And another side-note, it is pretty useless to use task configuration avoidance (tasks.register) if you then right away call .get() on the providers and thus force immediate realization. Instead user methods like configure(), map(), or flatMap().