简体   繁体   中英

gradle exclude external resource folder from all jars

Using gradle 5.4 with a project dependency from external folder in a netbeans project.

The external folder contains resources like images, xml and custom objects that can only be created by this netbeans project. These external assets are then used to create binary files that get packed into a separate jar by that netbeans project.

These same external resources are also used during runtime for development in the gradle project. While I need the resources for development in the gradle project, I do not need or want them to be included in any jars anywhere for any reason when using the task build command because only the binaries are needed for distribution.

How to exclude the external resources from any and all jar files in the gradle project but allow them to be used for the classPath so I can run the project?

Some code examples of failure.

apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'idea'

sourceSets { 
   main { 
      resources { 
         srcDir '../ExternalResourceFolder/assets' 
      } 
   }   
}

jar {
    exclude('../ExternalResourceFolder/assets/**')
}
dependencies {
    runtimeOnly files('../ExternalResourceFolder/assets') 
}

jar {
    exclude('../ExternalResourceFolder/assets/**')
}
distributions {
    main {
        contents {
            exclude '../ExternalResourceFolder/assets/**'
        }
    }
}

Tried many more things like adding to classPath and exclude but it would just be clutter to add them. Changing from sourceSet to dependency only moves the problem around from "build/lib" folder to "build/distributions" folder.

Had to exclude per file type in the end.

    sourceSets {
    main {
        resources {
            srcDir '.'
            exclude ('**/*.j3odata','**/*.mesh','**/*.skeleton',\
                    '**/*.mesh.xml','**/*.skeleton.xml','**/*.scene',\
                    '**/*.material','**/*.obj','**/*.mtl','**/*.3ds',\
                    '**/*.dae','**/*.blend','**/*.blend*[0-9]','**/*.bin',\
                    '**/*.gltf')
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM