This message was deleted.
# community-support
s
This message was deleted.
v
Don't use plain
File
type for your properties. Use
RegularFile
and then link them together. Then it should work properly
j
Thanks for the reply, Even with RegularFile it does not help. I am getting the same error says "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 568ms 1 actionable task: 1 executed
Do I have to consider anything special here?
v
How does your code look now? (Please use code tags, not plain text)
j
Thank you for the reply, I modified the code as you suggested but it does not work as expected (see console output). Could you please have look of my code and help me?
Task :addQuoteSource FAILED
FAILURE: 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
Copy code
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());
    }
}
Copy code
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;
    }
}
v
Sorry, I mistyped, I meant
RegularFileProperty
, 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()
.