When Junit is installed, it adds a symbolic link to the junit jar in /usr/share/ant/lib/. However, it does not update /usr/share/ant/package.env to include this new symlink. As a result, the /usr/bin/ant script does not include the Junit classes in the classpath, because it uses java-config to build the classpath.
I'm trying to use junit ant tasks and it's failing with the error message: Ant could not find the task or a class this task relies upon. This is common and has a number of causes; the usual solutions are to read the manual pages then download and install needed JAR files, or fix the build file: - You have misspelt 'junit'. Fix: check your spelling. - The task needs an external JAR file to execute and this is not found at the right place in the classpath. Fix: check the documentation for dependencies. Fix: declare the task. - The task is an Ant optional task and optional.jar is absent Fix: look for optional.jar in ANT_HOME/lib, download if needed - The task was not built into optional.jar as dependent libraries were not found at build time. Fix: look in the JAR to verify, then rebuild with the needed libraries, or download a release version from apache.org - The build file was written for a later version of Ant Fix: upgrade to at least the latest release version of Ant - The task is not an Ant core or optional task and needs to be declared using <taskdef>. Remember that for JAR files to be visible to Ant tasks implemented in ANT_HOME/lib, the files must be in the same directory or on the classpath Please neither file bug reports on this problem, nor email the Ant mailing lists, until all of these causes have been explored, as this is not an Ant bug. I have both junit and ant installed. I've tried rebuilding ant when junit was on the classpath. I've fiddled about with classpaths to no end even trying to call ant manually with a classpath containing about junit and ant and none of it works. I tried adding /usr/share/ant/lib/junit.jar to ant's package.env but it didn't make a difference. Ant claims to include all libraries in ANT_HOME/lib so including it in package.env shouldn't make a difference. Have you managed to get ant running with junit on Gentoo?
Yes, I have Ant working with Junit on Gentoo. I agree that the packages do not work together well now. The reason is that there is a circular dependency. Unless junit.jar is in the classpath when Ant is compiled, the junit tasks will not be built into Ant's optional.jar. However, the Junit ebuild depends on Ant. To get around this, you must do the following: 1) Emerge Junit. 2) Emerge Ant again, using the ebuild attached to Bug #10364. This fixes the Ant ebuild to check for an installed junit.jar and include it in the build classpath, so that the Junit tasks will be included in Ant's optional.jar. 3) Finally, update /usr/share/ant/package.env to include the junit.jar as explained in this bug report. The reason this is necessary is that the ant script in the gentoo package uses the "java-config --classpath" mechanism to set Ant's classpath, NOT using all jars ANT_HOME/lib as the standard Ant script does. Once you've done these things you should be able to use Junit with Ant. This would be a lot easier to deal with if the Ant and Junit ebuilds just installed the binary packages rather than compiling from source. There is really very little advantage in compiling Java applications and libraries from source. It's definitely not worth the problems caused, like this one.
The circular dependency problem has been kludged for the time being. Here's how you work around it (assuming you have neither ant nor junit installed) 1. emerge ant-1.5.3-r3 2. emerge junit 3. emerge ant-1.5.3-r3 The second time you merge ant, it will find the junit classes and add them appropriately to the package.env. But since Junit hasn't been installed by step 1, and since Junit requires ant to compile, it has to be run a second time. I am looking into ways that circular dependencies like this can be solved (we have other such conditions elsewhere in the Portage tree... this is just one, and my way of solving it is unique to Java.)
This appears to be a problem again with ant-1.5.3-r5