I needed to run a Java program as part of the build process, and there was too much baggage in the application plugin.
I made fidde with the application plugin, but in the end I used the much less "invasive" JavaExec plugin .
I have a class file MyObfuscator.class
in build.outputDirectory
, and before that I had a pom.xml
that performed code obfuscation in the assembly directory with two parameters:
<project> ... <build> ... <plugins> ... <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.2.1</version> <executions> <execution> <id>obfuscate</id> <phase>package</phase> <goals> <goal>exec</goal> </goals> <configuration> <executable>java</executable> <workingDirectory>${project.build.outputDirectory}</workingDirectory> <arguments> <argument>-Djava.library.path=.</argument> <argument>-classpath</argument> <argument>${project.build.outputDirectory}:lib.jar</argument> <argument>MyObfuscator</argument> <argument>HELLO</argument> <argument>GOODBYE</argument> </arguments> </configuration> </execution> </executions> </plugin> ... </plugins> </build> ... </project>
I welded this in this article in Gradle:
apply plugin: "java"
If you need to perform parameterized execution, as in the Maven example above, add a few lines to the task:
task obfuscate(type: JavaExec) {
Then depend on the assemble
task on obfuscate
(put this line somewhere below the obfuscate
task definition):
assemble.dependsOn obfuscate
Or let the task (earlier) jar
depend on it. See the chart below this section of the docs here for more ideas on where to do this.
Then you can call gradle as gradle build -PPARAM1=HELLO
to start the parameterized build.
grandchild May 22 '17 at 21:36 2017-05-22 21:36
source share