Issue
I have an multi-project Gradle build based on Java code. It's organized into several projects in order to preserve third party dependencies while still allowing for shared code. (There are main() functions in each subcomponent.) Here's my project folder structure on disk, which I believe follows all the Gradle and Java best-practices:
+---repository_for_component +---component | +---src | +---main | +---java | +---com | +---company | +---product | +---component | +---SharedSource.java +---subcomponent1 | +---src | +---main | +---java | +---com | +---company | +---product | +---component | +---subcomponent1 | +---Source1.java +---subcomponent2 | +---src | +---main | +---java | +---com | +---company | +---product | +---component | +---subcomponent2 | +---Source2.java +---build.gradle +---settings.gradle ...
One of our devs prefers not to use an IDE (terminal only), and this is understandably a huge pain for him to navigate. It's painful for me too when I have to do anything from the command line or use a file browser.
Because this repository is only for the "component" in question, much of the paths are redundant. In particular, this eliminates 4 redundant folders:
+---repository_for_component +---subcomponent1 | +---src | +---main | +---java | +---com.company.product.component.subcomponent1 | +---SharedSource.java ...
It's still a marginal improvement, but it's something. I'd press my luck farther, but while Gradle builds this project just fine, Eclipse gives the error:
The declared package "com.company.product.component.subcomponent" does not match the expected package ""
Are there any workarounds I can use within Eclipse? Or other suggestions for ways to make this less painful for everyone?
Solution
I've confirmed that Eclipse only supports source paths that match the package names; alternatives have been requested and marked as "Won't Fix."
I think I've found a suitable workaround for Linux developers wishing to do their work from the command line. In your ~/.bashrc
file, add something like this:
# Project shortcuts export repo="/path/to/repository/" alias repo_root="cd $repo" alias repo_core="cd $repo/core/src/main/java/com/company/product/component/" alias repo_sub1="cd $repo/sub1/src/main/java/com/company/product/component/subcomponent1" alias repo_sub2="cd $repo/sub2/src/main/java/com/company/product/component/subcomponent2"
Once you have the paths set, start a new terminal instance, and run it like this:
bash-4.1$ repo_root bash-4.1$ pwd /path/to/repository bash-4.1$ repo_sub1 bash-4.1$ pwd /path/to/repository/sub1/src/main/java/com/company/product/component/subcomponent1
Alternatively, you could use export
for each of them instead of aliases. Whatever cans your peaches. The point is that you can quickly traverse those paths much faster and do so from anywhere.
Answered By - Logical Fallacy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.