Set Ant property from Gradle not working - ant

I'm converting our build from Ant to Gradle. Our first step is to add the Gradle build files so we can start using Gradle as our build tool. This lets us use our existing build scripts to build using Ant and convert them to Gradle over time. I want to simply have Gradle call the existing Ant build files. Our projects are all NetBeans projects, which have build.xml and nbproject/build-impl.xml files. Some of the projects require NetBeans build properties, which can be found at ~/.netbeans/6.5.1/build.properties. I currently have build.gradle which contains only this:
ant.importBuild 'build.xml'
I can build the project using Ant like this:
ant -Duser.properties.file=/home/me/.netbeans/6.5.1/build.properties dist
However, when I build with Gradle, Ant complains it cannot find the properties set in build.properties. I've tried setting the Ant property, but it doesn't seem to get picked up:
ant.properties['user.properties.file'] = '/home/me/.netbeans/6.5/build.properties'
I've also tried setting a system property:
systemProperties 'user.properties.file': '/home/me/.netbeans/6.5/build.properties'
but this doesn't work either. Ideally I'd like to set this property in ~/.gradle/gradle.properties as just about all of our projects need it.
How can I set this property in Gradle and have Ant pick it up when called from Gradle?

If you want to set load the properties on multiple Gradle projects you could use a Gradle init script, http://www.gradle.org/docs/current/userguide/init_scripts.html. Inside the init script you would put this code:
allProjects {
ant.properties['user.properties.file'] = '/home/me/.netbeans/6.5/build.properties'
}

Related

Configure Jenkins to run Visual Studio bat file before Maven job

I have a Maven module that utilizes the NAR plugin to build some JNI libraries, and in Jenkins I have configured a Maven project to build this module. In order for these libs to be built, the Visual Studio bat file that sets up the path and other environment variables must be run. I have tried several different ways to get this bat file to execute before the Maven commands are called, and none of them have worked correctly. I know that Jenkins isolates all of the build process steps, so it can be difficult to get the environment set up, but I'm hoping someone has solved this particular issue. Here's what I've tried:
calling the bat file as a pre build step.
Using the EnvInject plugin to call the bat file, both as a pre build step and as a pre job step.
Setting the environment variables directly without calling the bat file using EnvInject.
calling the bat file from the mvn.bat file (this failed because it appears Jenkins will call Maven directly, without using the bat file).
As a workaround, I'm using the Freeform project type and setting the build steps to
call the bat file.
Directly call maven with appropriate parameters.
This works, but it's not as nice as using the Maven project type, ex. a failed unit test will fail the entire build instead of just sending a warning. Is there a way to configure this as a Maven project?

How to Sync InteliJ Build with Generated Ant?

Using IntelliJ 14, I successfully generated Ant XML from what was in the Project Structure Artifacts GUI. I can run Ant targets and have successfully modified the Ant XML. Now Build -> Make Project gives me pre-ant-modification results. I expected IntelliJ to use or stay in sync with the Ant XML after generating it. Is there a way to get that effect?
No, there is no way to import the modifications of an Ant file into the IntelliJ IDEA project model. IntelliJ IDEA's build does not use Ant in any way, and in general the structure of Ant files is much more general than what's supported by IntelliJ's project model.
What you can do is stop using IntelliJ's Make Project action and always build your project through Ant from IntelliJ. To do this, run "Add as Ant build file" action on your generated build file, and run build actions from the Ant toolwindow. Then, in your run configurations, you can replace "Before launch: Make" with "Before launch: Run Ant target".

Gradle Ant Cannot add task ':myproject:test' as a task with that name already exists

I'm trying to Gradle-ize our build by using Gradle to execute the Ant build. I'm using the java plugin so I can set source/target and I'm using ant.importBuild 'build.xml'. When I execute Gradle, I get the error above. I understand that both Ant and Gradle have these targets/tasks in common: clean, jar, javadoc, test. One option is to change the Ant target names in build.xml, but I'm hoping there's an easier way as I have a lot of projects and build files. I found this "wrapper" solution (http://issues.gradle.org/browse/GRADLE-771), but this did not work for me. How can I solve this?
Your options are:
Do not apply the plugin to the same project that imports the Ant build.
Rename the conflicting targets in the Ant build script.
You can rename all the ant targets:
ant.importBuild('build.xml') { String oldTargetName ->
return 'ant_' + oldTargetName
}

How to install gradle-grails-plugin?

Complete gradle nooby here.
I want to be able to execute grails build commands like "grails compile", "grails test-app" and so forth from gradle.
I found the grails-gradle-plugin from Peter Ledbrook at: https://github.com/grails/grails-gradle-plugin.
Cloning the repository I get some files and folders. In the readme file it says " include the required JARs via buildscript {} and 'apply' the plugin". The apply part sure I get but how do I add the JAR? And which jar? Do I need to use gradle on the build file in the folder of the downloaded plug-in and compile a jar? And ones I get the jar where do I place it and how do I include it in my projects build.gradle file?
I have a feeling this is going to be ridiculously easy but I just can't get it to work.
In Gradle, the jars are added to build script or to your application class path through dependencies closure e.g.
dependencies {
compile "org.grails:grails-crud:1.3.4"
compile "org.grails:grails-gorm:1.3.4"
compile "ch.qos.logback:logback-core:1.0.7"
compile "org.slf4j:slf4j-api:1.7.2"
}
compile is a name of one of the many configurations (there are also test, runtime etc.) and e.g. "org.grails:grails-crud:1.3.4" is a reference to a jar in one of the public repositories, which are also specified in your scripts in repositories closure.
You can read more about Gradle dependency management in http://gradle.org/docs/current/userguide/dependency_management.html.
For your Grails project you need to define a build.gradle file which looks similar to what is described in the README.
Though I tried today to just create a simple Grails project using that plugin and gradle init command and it didn't work. I have created an issue for that: https://github.com/grails/grails-gradle-plugin/issues/16.

Can we use pom.xml into ANT

I know that, we can very well use ANT and Maven together to build the project.We can run ANT scripts through Maven's POM.xml. But my question is can we run pom.xml through ANT's build.xml ?
i.e. can we create maven build from build.xml
Yes, using maven ant tasks.
The page lists out multiple maven tasks which can be integrated into an ant build script, thus combining the features of both. To take an example, there is the mvn task, which as documented can do a full maven build from ant.
<artifact:mvn mavenHome="/path/to/maven-3.0.x">
<arg value="install"/>
</artifact:mvn>
Besides this, there are
Dependencies task
Install and Deploy tasks
Pom task
each described with examples.
Maven and ANT are very different build tools. In ANT you write all the logic yourself, whereas a standard build process is "baked in" with Maven.
The POM file contains no logic, instead it contains a series of declarations about your project.
If you understand well how Maven works, it is theoretically possible to take a POM and generate an ANT build that emulates the behaviour of the Maven build. I'm not aware of any solution which can easily convert in the other direction, mainly because ANT is missing Maven functionality, such as dependency management.
Instead of trying to convert an ANT build into Maven, I'd recommend that you keep your existing build logic and delegate the management of your classpath to the ivy or Maven ANT tasks. These tools also provide tasks to publish your build output to a Maven repository, enabling your project to share with other projects using Maven.
Finally, I'm an ivy advocate and wrote an ant2ivy script which can assist in upgrade process. It creates an initial set of configuration files for downloading your projects dependencies from the Maven central repository.

Resources