Using Spring in Gradle plugin


(Sergey) #1

Hello.
I try to use Spring in my own Gradle plugin. When I start up test it works perfect:

public void testGenerateEntityTask() throws IOException {
        BuildResult result = GradleRunner.create()
                .withProjectDir(new File("d:\\gitlab\\1"))
                .withArguments("generateEntity")
                .withDebug(true)
                .build();
        assertEquals(result.task(":generateEntity").getOutcome(), SUCCESS);
}

But when I start up a task from my application that use the Gradle I get an error message:

IOException parsing XML document from class path resource [application-context.xml]; nested exception is java.io.FileNotFoundException: class path resource [application-context.xml] cannot be opened because it does not exist

The error happens at a line:

context = new ClassPathXmlApplicationContext("application-context.xml");

File application-context.xml exists in the plugin jar.

My questions: how can I use the power of Spring in my Gradle task? How do I transfer the file into context of my application?
Thanks.