LK__
LK__

Reputation: 6713

Getting location of cross-project resources

I have read many similar questions where the reply is that the project structure is not ideal so my questions based on the following:

I have a main project (ProjA) which needs to include a second project (ProjB) which is not a child project. ProjB has various resource files which need to be copied in the distribution of ProjA.

build.gradle of ProjA

dependencies {
    compile project(":ProjB")
}    

distributions {
    main {
        baseName = "Something"
        contents {
            into('bin') { from jar.archivePath }
            into('lib') { from configurations.runtime }
            into('etc') {
                from ('../../projb/src/main/webapp') // Fix me!
            }
        }
    }
}

1.) Ideally ProjB should expose the location of the resource files through a property used by ProjA, how can this be done?

2.) Is this the correct way to do it as I have read alot about cross-project properties not being ideal - or should I be doing something completely different?

Upvotes: 1

Views: 62

Answers (1)

Opal
Opal

Reputation: 84756

Don't know if it helps but it seems that the best way is to do it in the following way:

distributions {
    main {
        baseName = "Something"
        contents {
            into('bin') { from jar.archivePath }
            into('lib') { from configurations.runtime }
            into('etc') {
                from project(':projB').file('src/main/webapp')                
            }
        }
    }
}

The path must be hardcoded in that case.

Second option might be specifying a project property - in general not a very good idea - and use in another project - there must be also evaluation order defined.

In projB

ext.resourcesDir = project.file('src/main/webapp2')

and in projA

evaluationDependsOn(':projB')

and:

distributions {
    main {
        baseName = "Something"
        contents {
            into('bin') { from jar.archivePath }
            into('lib') { from configurations.runtime }
            into('etc') {
                from project(':projB').file('src/main/webapp')                
                from project(':projB').resourcesDir
            }
        }
    }
}

Here's complete example.

Upvotes: 1

Related Questions