Problem with jar that contains java sources

My java project depends on other jar files that contains java classes and its sources. When i compile my project it always tries to compile the java source files from the jar file. Is there a way to prevent gradle from compiling the source files in the jar?

Can you provide more information, including your build script? Gradle won’t do that normally. I think you’d even have to unjar the sources to make it “work”.


Yes of course… here my build.gradle. The iengine.jar file contains the java classes and sources. When I manually remove the java sources in the jar I can build my project otherwise it throws “not found exception” from the java files in the jar file.

apply plugin: ‘java’ version = ‘1.0’ sourceCompatibility = 1.5 jar {

manifest {

attributes ‘Implementation-Title’: ‘JaxWS Dynamic Client’, ‘Implementation-Version’: version

} } sourceSets {

main {

java {

srcDir ‘src/main’



test {

java {

srcDir ‘src/test’




repositories {


ivy {

name = ‘ivyRepo’

artifactPattern “file://[organisation]/[module]/[type]s/[artifact]-[revision].[ext]”

} }

dependencies {


compile files(‘lib/iengine.jar’) }

def ivyDependencies(conf) {

def dep = []

def ivyModule = new XmlParser().parse(file(“ivy.xml”))

ivyModule.dependencies.dependency.each {

if(it.@conf == null || it.@conf == conf)

dep.add(it.@org + ‘:’ + it.@name + ‘:’ + it.@rev)


return dep }

Can you post the Gradle build output too, including the error message(s)? Not sure what’s happening here. It’s not uncommon for Jars to contain the source code, but I’ve never seen it cause a problem.

Hope this output helps. gradle output with --info argument.

C:\dev\ie8\services\jaxwsdynclient>gradle assemble --info Starting Build Settings evaluated using empty settings file. Projects loaded. Root project using build file ‘C:\dev\ie8\services\jaxwsdynclient\build.gradle’. Included projects: [root project ‘jaxwsdynclient’] Evaluating root project ‘jaxwsdynclient’ using build file ‘C:\dev\ie8\services\jaxwsdynclient\build.gradle’. All projects evaluated. Starting build for primary task ‘assemble’. Tasks to be executed: [task ‘:compileJava’, task ‘:processResources’, task ‘:classes’, task ‘:jar’, task ‘:assemble’] :compileJava :: loading settings :: url = jar:file:/C:/dev/tools/gradle-1.0-milestone-3/lib/ivy-2.2.0.jar!/org/apache/ivy/core/settings/ivysettings.xml :: resolving dependencies :: tie#jaxwsdynclient;1.0

confs: [compile]

found oracle#weblogic;10.3.5 in ivyRepo

found;2.1 in clientModuleChain

found javax.xml.bind#jaxb-api;2.1 in clientModuleChain

found;1.0-2 in clientModuleChain

found javax.activation#activation;1.1 in clientModuleChain

found;2.1.4 in clientModuleChain

found com.sun.xml.bind#jaxb-impl;2.1.7 in clientModuleChain

found com.sun.xml.messaging.saaj#saaj-impl;1.3.1 in clientModuleChain

found javax.xml.soap#saaj-api;1.3 in clientModuleChain

found activation#activation;1.0.2 in clientModuleChain

found;0.7 in clientModuleChain

found org.jvnet.staxex#stax-ex;1.2 in clientModuleChain

found;1.0.1 in clientModuleChain

found;20050927 in clientModuleChain

found org.jvnet#mimepull;1.2 in clientModuleChain

found log4j#log4j;1.2.14 in ivyRepo

found junit#junit;4.9 in MavenRepo

found org.hamcrest#hamcrest-core;1.1 in MavenRepo :: resolution report :: resolve 1154ms :: artifacts dl 0ms

:: evicted modules:

javax.activation#activation;1.0.2 by [javax.activation#activation;1.1] in [compile];1.0 by [;1.0-2] in [compile]

junit#junit;3.8 by [junit#junit;4.9] in [compile]









| number| search|dwnlded|evicted|| number|dwnlded|




21 |











--------------------------------------------------------------------- Executing task ‘:compileJava’ due to: Output file C:\dev\ie8\services\jaxwsdynclient\build\classes\main\ch\tie\service\jaxws\dynclient\JAXWSDynamicClient.class has been removed for task ‘: compileJava’. [ant:javac] Compiling 1 source file to C:\dev\ie8\services\jaxwsdynclient\build\classes\main ch\tie\iengine\server\db\\tie\iengine\server\ package javax.servlet.http does not exist import javax.servlet.http.HttpServletRequest;

^ ch\tie\iengine\server\db\\tie\iengine\server\ package javax.servlet.http does not exist import javax.servlet.http.HttpSession;

^ ch\tie\iengine\server\db\\tie\iengine\server\ package oracle.jdbc does not exist import oracle.jdbc.OracleConnection;

^ ch\tie\iengine\server\db\\tie\iengine\server\ package oracle.jdbc does not exist import oracle.jdbc.OraclePreparedStatement;

^ ch\tie\iengine\server\db\\tie\iengine\server\ package oracle.jdbc.pool does not exist import oracle.jdbc.pool.OracleDataSource;

^ ch\tie\iengine\server\db\\tie\iengine\server\ package oracle.sql does not exist import oracle.sql.BLOB;

^ ch\tie\iengine\server\db\\tie\iengine\server\ package org.apache.commons.configuration does not exist

import org.apache.commons.configuration.XMLConfiguration;

^ ch\tie\iengine\server\db\\tie\iengine\server\ package does not exist import;

^ ch\tie\util\\tie\ package oracle.jdbc does not exist import oracle.jdbc.OracleTypes;

^ ch\tie\util\\tie\ package oracle.sql does not exist import oracle.sql.ARRAY;

^ ch\tie\util\\tie\ package oracle.sql does not exist import oracle.sql.BLOB;

^ ch\tie\util\\tie\ package oracle.sql does not exist import oracle.sql.CLOB;

^ ch\tie\util\\tie\ package oracle.sql does not exist import oracle.sql.TIMESTAMPLTZ;

^ ch\tie\iengine\util\\tie\iengine\ package javax.servlet.http does not exist import javax.servlet.http.HttpSession;

^ ch\tie\iengine\server\\tie\iengine\ package javax.servlet.http does not exist import javax.servlet.http.HttpServletRequest;


… More Errors …

Note: Recompile with -Xlint:deprecation for details. Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 100 errors 4 warnings

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ‘:compileJava’. Cause: Compile failed; see the compiler error output for details.

  • Try: Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.


Total time: 16.303 secs

C:\dev\ie8\services\jaxwsdynclient>gradle assemble --info

Here is also the javac part from gradle --debug output.

23:34:40.894 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Adding reference: compile.classpath 23:34:40.988 [DEBUG] [org.gradle.api.internal.tasks.compile.AntJavaCompiler] Running ant javac with the following options {includeAntRuntime=false, de stdir=C:\dev\ie8\services\jaxwsdynclient\build\classes\main, classpathref=compile.classpath, sourcepath=, target=1.5, source=1.5, failonerror=true, ve rbose=false, listfiles=false, deprecation=false, nowarn=false, optimize=false, debug=true, fork=false, includeJavaRuntime=false} 23:34:41.112 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Class loaded from parent loade r (parentFirst) 23:34:41.144 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Class loaded from paren t loader (parentFirst) 23:34:41.159 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Class loaded from parent load er (parentFirst) 23:34:41.190 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Class loaded from pare nt loader (parentFirst) 23:34:41.222 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] fileset: Setup scanner in dir C:\dev\ie8\services\jaxwsdynclient\src\main

with patternSet{ includes: [] excludes: [] } 23:34:41.268 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] [ant:javac] tie\service\jaxws\dynclient\ added as tie\service\jaxws\dynclient\JAXWSDynamicClient.class doesn’t exist. 23:34:41.300 [INFO] [org.gradle.api.internal.project.ant.AntLoggingAdapter] [ant:javac] Compiling 1 source file to C:\dev\ie8\services\jaxwsdynclient\ build\classes\main 23:34:41.315 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] [ant:javac] Using modern compiler 23:34:41.362 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] [ant:javac] Compilation arguments: ‘-d’ ‘C:\dev\ie8\services\jaxwsdynclient\build\classes\main’ ‘-classpath’ ‘C:\dev\ie8\services\jaxwsdynclient\build\classes\main;C:\dev\ie8\services\jaxwsdynclient\lib\iengine.jar;C:\Users\tiezad.TIE.gradle\cache\oracle\web logic\jars\weblogic-10.3.5.jar;C:\Users\tiezad.TIE.gradle\cache\\jaxws-api\jars\jaxws-api-2.1.jar;C:\Users\tiezad.TIE.gradle\cache\javax .xml.bind\jaxb-api\jars\jaxb-api-2.1.jar;C:\Users\tiezad.TIE.gradle\cache\\stax-api\jars\stax-api-1.0-2.jar;C:\Users\tiezad.TIE.grad le\cache\javax.activation\activation\jars\activation-1.1.jar;C:\Users\tiezad.TIE.gradle\cache\\jaxws-rt\jars\jaxws-rt-2.1.4.jar;C:\User s\tiezad.TIE.gradle\cache\com.sun.xml.bind\jaxb-impl\jars\jaxb-impl-2.1.7.jar;C:\Users\tiezad.TIE.gradle\cache\com.sun.xml.messaging.saaj\saaj-impl\ jars\saaj-impl-1.3.1.jar;C:\Users\tiezad.TIE.gradle\cache\javax.xml.soap\saaj-api\jars\saaj-api-1.3.jar;C:\Users\tiezad.TIE.gradle\cache\com.sun.xml .stream.buffer\streambuffer\jars\streambuffer-0.7.jar;C:\Users\tiezad.TIE.gradle\cache\org.jvnet.staxex\stax-ex\jars\stax-ex-1.2.jar;C:\Users\tiezad. TIE.gradle\cache\junit\junit\jars\junit-4.9.jar;C:\Users\tiezad.TIE.gradle\cache\org.hamcrest\hamcrest-core\jars\hamcrest-core-1.1.jar;C:\Users\tiez ad.TIE.gradle\cache\\sjsxp\jars\sjsxp-1.0.1.jar;C:\Users\tiezad.TIE.gradle\cache\\resolver\jars\res olver-20050927.jar;C:\Users\tiezad.TIE.gradle\cache\org.jvnet\mimepull\jars\mimepull-1.2.jar;C:\Users\tiezad.TIE.gradle\cache\log4j\log4j\jars\log4j -1.2.14.jar’ ‘-target’ ‘1.5’ ‘-g’ ‘-source’ ‘1.5’

The ’ characters around the executable and arguments are not part of the command. 23:34:41.424 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] [ant:javac] File to be compiled:

C:\dev\ie8\services\jaxwsdynclient\src\main\tie\service\jaxws\dynclient\ 23:34:44.466 [ERROR] [system.err] ch\tie\iengine\server\db\\tie\iengine\server\ package javax.servlet .http does not exist 23:34:44.498 [ERROR] [system.err] import javax.servlet.http.HttpServletRequest; 23:34:44.513 [ERROR] [system.err]

^ 23:34:44.529 [ERROR] [system.err] ch\tie\iengine\server\db\\tie\iengine\server\ package javax.servlet .http does not exist 23:34:44.544 [ERROR] [system.err] import javax.servlet.http.HttpSession; 23:34:44.560 [ERROR] [system.err]

^ 23:34:44.716 [ERROR] [system.err] ch\tie\iengine\server\db\\tie\iengine\server\ package oracle.jdbc d oes not exist 23:34:44.934 [ERROR] [system.err] import oracle.jdbc.OracleConnection;

One possible thing to check is the timestamps of the sources vs. the classes in the jar. If the sources are newer than the classes, then javac will try to recompile them. We ran into this in our Ant build system…

Yes the sources are 1 sec newer then the classes… :slight_smile: … How did you solve it… unjar the jar and remove the source files?

In our case, the sources were from our own builds, so I made sure that they had their original timestamps when we jarred them. You could process the jars and set the timestamps for all sources to effectively 0, somewhere back in 1980 when DOS began. They would still work as source for IDEs, but the dates would be old and would never bother javac.