Distribution plugin: separate project and external library dependencies

I have a multi project build and need to place my project jars into one directory and library jar into the other directory.

I tried do this:

project(':someProj') {
  distributions {
    main {
      contents {
        into('jars') {
          from(project.configurations.compile.copyRecursive(DependencySpecs.type(Type.EXTERNAL)))
        }
      }
    }
  }
}

But as a result I receive an error

Could not get unknown property ‘DependencySpecs’ for object of type org.gradle.api.internal.file.copy.CopySpecWrapper_Decorated

Variant 2:

 distributions {
    custom {
      contents {
        into(file('libsDir')) {
          from {
            subprojects.collect {
              it.configurations.compile.copyRecursive(DependencySpecs.type(Type.EXTERNAL))
            }
          }
        }
      }
    }
  }

Was successfully compiled, but ‘installCustomDist’ do nothing:

Skipping task ‘:myproject:installCustomDist’ as it has no source files.

Also I tried copy task:

  task libs(type: Copy) {
    File libsDir = file('libsDir')
    into libsDir
    from {
      subprojects.collect {
        it.configurations.compile.copyRecursive(DependencySpecs.type(Type.EXTERNAL))
      }
    }
  }

This was successful compiled, but there is no result.

Can someone help me?

Hi,

I’m not sure about the layout of your project but calling suprojects in a module can’t work.

Are you using the plugin from the parent ?
If not you should jump into the rooProject before to be able to call subprojects.

This should do the job.

 distributions {
     custom {
       contents {
         into('libsDir') {
           rootProject.subprojects{ module ->
               from {"${module.buildDir}/libs"}
           }    
         }
       }
     }
   }