Gradle: How to make the compilation area file dependency excluded from packaging?

I have a multi-module gradle project with the following basic structure:

root core c-interface m-interface 

C-interface and m-interface depend on the main project:

 compile project(':root:core') 

The c-interface and m-interface use the WAR plugin, but the kernel is not and is only a jar.

In the main project, I deal with some file system dependencies with the following. One of these dependencies, which I cannot pack into WAR, generated by the c-interface and m-interface. I used to have this dependency in the nexus maven repository, so I could exclude it by group, name, version in the given run-time configuration in the c-interface and m-interface.

I cannot figure out how to do the same for a file dependency. The gradle dependencies task does not display dependencies between files, so I don’t know what I would invest in the provided runtime.

I am reading http://issues.gradle.org/browse/GRADLE-471 , but trying to use this idea does not seem to delete the archive from my packages. Here is what I am defining now (in core build.gradle):

 compile fileTree(dir: 'dependencies/compile/archive', include: '*.jar', exclude: 'management.jar') compile(files('dependencies/compile/archive/management.jar')){ notPackaged = true } // Excludes it from all publications 

Update

provided Compile without war plugin looked like an opportunity. I installed this in the build.gradle kernel and compiled it perfectly, but the c-interface and m-interface also needed dependencies at compile time. Including the file as provided by Compile (or even checking the health with compilation) in the c-interface and m-interface did not fix compile-time errors due to the absence of the management.jar dependency. My assumption is that it was already limited as provided by Compile in the kernel, that new declarations are ignored in the c-interface and m-interface.

kernel /build.gradle:

 configurations { providedCompile } dependencies { providedCompile files('dependencies/compile/archive/management.jar') } sourceSets.main.compileClasspath += configurations.providedCompile sourceSets.test.compileClasspath += configurations.providedCompile sourceSets.test.runtimeClasspath += configurations.providedCompile 

C interface / build.gradle:

 providedCompile files('dependencies/compile/archive/management.jar') 
+4
source share
1 answer

There is probably a cleaner and simpler solution, but you can specify a custom configuration:

 configurations { compileOnly } 

and then specify all the dependencies:

 dependencies { compile fileTree(dir: 'dependencies/compile/archive', include: '*.jar', exclude: 'management.jar') compileOnly files('dependencies/compile/archive/management.jar') } 

Finally, add compileOnly configuration in the classpath of all source sets

 sourceSets.all { compileClasspath += configurations.compileOnly } 

Therefore, management.jar should be on the compilation path, but will not be packaged.

EDIT Only now I fully understand your problem. The following worked for me in a test project.

In the gradle main project file:

 repositories { flatDir { dirs 'dependencies/compile/archive' } } dependencies { compile fileTree(dir: 'dependencies/compile/archive', include: '*.jar', exclude: 'management.jar') compile ':management:' } 

In a project that depends on the kernel:

 repositories { flatDir { dirs new File(project(':core').projectDir, 'dependencies/compile/archive') } } dependencies { compile(project(':core')) { exclude module: 'management' } compileOnly ':management': } sourceSets.all { compileClasspath += configurations.compileOnly } 
+13
source

All Articles