Build NetBeans Ant Project from Gradle - netbeans

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 have the NetBeans user.properties.file property successfully set to ~/.netbeans/6.5.1/build.properties.
When I build with Ant, I invoke this:
ant -Duser.properties.file=~/.netbeans/6.5.1/build.properties dist
This executes the dist target, which depends on the init target which depends on the targets listed below:
pre-init, init-private, init-userdir, init-user, init-project, do-init, post-init, init-check, -init-taskdefs
The targets listed above are executed in the order specified. When I invoke 'gradle dist', it invokes the init Ant target, but then it executes the targets listed above in reverse order, starting with -init-taskdefs. There are required properties which are setup in the targets before the -init-taskdefs target which aren't being setup when run from gradle.
Really, all I want to do right now is to use gradle to invoke Ant to build my projects. What's the best way to do this since using gradle to build using Ant build.xml files doesn't seem to work as expected? Do I have to resort to using exec? (I hope not).

I found trying to use Gradle's integration of Ant with a Netbeans project was too difficult and error prone. Instead, I use Gradle's exec() command. Below is an example, lifted from my code that builds a NetBeans Project named 'Common Library'.
task commonLibrary {
doLast {
ant.echo("Building Common Library")
exec () {
workingDir = "../netbeans/nb/CommonLibrary"
executable = "ant"
args = ['clean', 'jar']
}
}
}
I realize that wasn't the answer you were hoping for, but posted it as a possible solution for other people, particular people who aren't in a position to start reworking their build.xml files.

Related

Unittest an entire netbeans application including dependent projects

Here is the situation:
I have a java application (netbeans project) that uses several java libraries (each of them is a netbeans project). I have an automated build script that builds the application using ant without the netbeans IDE. The command to build the application is
ant jar
That works fine, it recursively builds jars for all dependent libraries and finally the application jar.
Now, I want to run all my unit tests in the automated build. The default ant target depends on the targets jar, test, and javadoc, so I thought I could simply call
ant
as the build command. As before, all jars are built for the dependent libraries, but only the unit tests for the application project are executed (same for javadoc, btw.).
So, how do I get ant to run the unit tests for each dependent library project recursively?
Used versions are: netbeans 8, junit 4.
The only solution I found is to add a dependency into the build.xml used by ant for every library and the application project:
<target name="-pre-jar" depends="test" />
But that would mean to execute all tests on every build of a jar file. And since netbeans uses these build.xml files as well, every simple build would lead to executing all unit tests.
After some testing I think I've found a solution that works.
I had to add the following code into the build.xml of each netbeans project whose unit tests should be run (fyi: the build.xml is provided by netbeans for personal changes to the build process).
<target name="-pre-jar" depends="test-on-release" />
<target name="test-on-release" if="release.runtests">
<antcall target="test" />
</target>
Then, if I run ant on the commandline I have to define the property release.runtests to enable the execution of unittests:
ant -Drelease.runtests= jar
If I remove the definition of the property from the call, the target test-on-release is not executed and thus the tests are not run. The same happens when I use the netbeans IDE to build a project.
That said, it is a solution, not the solution, at least not the solution I had hoped for. It would be much more convenient if there was a way to run the test target recursively without having to edit all these build.xml files. Maybe that is not possible with the constraints given by the netbeans-generated build files.

Working on an Eclipse project (using Builders) in IntelliJ

I've recently been tasked with working on an existing eclipse project that makes use of Builders to run Ant tasks under given conditions. I've never heard of Builders before yesterday, and I'm having difficulties getting the project to work in IntelliJ.
First of all, I would like to know if there is a way I can effectively trick Ant into running from a different base directory than what it already does. Consider the following screenshot from Eclipse:
Here, project A is running an Ant task in a local build file that extends a build file from project B. As you can see from the Base Directory setting, it is different from that of A. When I try to run the task from this build file in IntelliJ, I get build errors because certain directories do not exist in the folder for project A -- they are located in project B.
Secondly, this Builder is set to trigger on Manual Build and Auto Build, but my understanding is that this only triggers if the project the builder is attached to gets built. As far as I can tell, in IntelliJ, I can set an Ant task to trigger before or after a build, but it seems like this will be for the whole project, instead of just the relevant module that represents this Eclipse project. Is there a way I can make it only apply to a given module, or will I have to trigger it for changes to all modules?

Eclipse build path missing

Hi I am working on a project and I have imported it via gitHub. I am importing it as a general project, it won't work otherwise. The problem I have is that there is no buildpath for the project. From java I can't run any of the files but I can run it fine in source tree with gradle.
I have read up on it and it says the way to fix it is:
Right-click > properties > build path
That or similar options but in my eclipse there is no BUILD PATH option.
I have tried looking at some fixes here and here. From the second link I have found that the following files are missing:
.classpath
.settings/*
If the project has a gradle wrapper in the root of the project then use it to invoke the tasks cleanEclipse eclipse to produce the eclipse artifacts.
Assuming you're on unix type system:
./gradlew cleanEclipse eclipse
If you're on windows, use gradlew.bat instead.
If the GitHub project didn't have a gradle wrapper, then you can use a system version of gradle instead.
This all assumes the project has following in it. If not add it to the main build script:
apply plugin: 'eclipse'

Eclipse execute Maven build with tests

In simple words: How to runs in eclipse tests with building process (as simple as possible)?
I want to execute test defined in pom with every maven build. Currently all is build, but none test is run. When I execute maven test it runs test, but during build it only builds.
How can I add this phase to eclipse build process?
I already read Eclipse Maven Build and Test with One Button, and it is close to optimal, still I would like to run tests with build to be more TDD.
My solution(might not be optimal):
require maven runpath
Go to Project -> Builders
Add new Program
In Edit configuration enter (as on picture):
Location: your/maven/path
arguments: test -f /yourProjectPomPath/pom.xml
As on picture tab Build Options -> Check(click) During auto builds option select
Save changes and check if all works

Netbeans project to scripted build

I'm trying to convert a Netbeans 6.9.1 project into a scripted build (without netbeans). Of course, it fails (or I wouldn't be asking for help).
In the failure it says that the org.apache.commons.httpclient package does not exist. (Of course, it worked when we ran the build in Netbeans).
Now I know exactly where the commons-httpclient.jar file is located in my project structure, but I can't seem to tell it to the compiler via the ant build files and the netbeans property files.
Perhaps related to this is when I ran "ant -v" to build my software, it said,
Property lib.mystuff.classpath has not been set. This variable is important, I guess, because
the file nbproject/project.properties uses lib.mystuff.classpath in its definition of javac.classpath, which of course tells the Java compiler where to find the JARs.
So...when moving a Netbeans project to a netbeans-independent scripted build, how can the build script set these properties? Also, how can I ensure that the jar file gets included in the ant build?
I appreciate any help I can get, as I am a Java newbie.
UPDATE AFTER ACCEPTING ANSWER FROM vkraemer:
There are a few best practices for build scripts for production software:
Put everything needed for a build under a single directory tree. (Netbeans = fail)
Put everything in source code control. (I did that)
The first line of the build script should clear all environment variables.
The next section of the build script should explicitly set all environment variables to values which are known to work.
The next part of the build should be able to execute using command-line programs such as javac, ant, cc, etc, and must not depend on firing up an IDE such as Eclipse or Netbeans.
It is a shame that Netbeans makes this hard.
I did a quick look in a Java Application project and found the following...
javac.classpath = ${libs.MyStuff.classpath}
libs.MyStuff.classpath is defined in %HOME%/.netbeans/6.9.1/build.properties.
You may be able to get by doing the following...
ant -Dlibs.MyStuff.classpath=c:\a\b\c.jar
You would need to do more if you have multiple jar files in the MyStuff library that you created in NetBeans.