This is a Vim plugin for Android development using Gradle as a build system, supporting Robolectric Unit Testing. It is based on the excellent hsanson/vim-android plugin, except that it is written mostly in ruby, is unit tested, and exclusively supports the Gradle build system. If you'd like to use ant/maven, or don't need unit-testing, maybe hsanson's plugin will do the trick.
NOTICE:
Since I'm no longer working with Android professionally, and the scale of the
java projects I am currently working on is way to mutch for Javacomplete, I'm
not using the plugin right now. The plugin is therefor currently in hiatus.
Pull requests are welcome though.
- Ruby 1.9.3+
- Android SDK installed with the $ANDROID_HOME environment variable set.
- Gradle 2.0+ (?) or a gradle wrapper in the project.
- exuberant-ctags for the
GrandTags
command. - scrooloose/syntastic for syntax checking.
- meonlol/javacomplete For code completion. My fork might still litter your :messages window a bit, but at least it works.
- Tim Pope's Dispatch vim-grand will run the appropriate commands through it, so vim doesn't get blocked. Highly recommended.
- YouCompleteMe for managing additional autocompletion features.
If you don't use one already, install a package manager plugin like Pathogen or Vundle. It makes installing as simple as:
Vundle:
- Add the line
Plugin 'hsanson/vim-android'
to your .vimrc - Call
:so %
on the updated .vimrc to reload it. - Run
:PluginInstall
to let vundle install it for you.
Pathogen:
Copy and past into the terminal:
cd ~/.vim/bundle
git clone git://github.com/tpope/vim-fugitive.git
vim -u NONE -c "helptags vim-fugitive/doc" -c q
:GrandSetup Sets up all the project paths for javacomplete and syntastic.
When used in combination with the grand.gradle
script, all paths defined in
your build.gradle will also be used for autocompletion and syntax checking.
:GrandTags Generates a tags file in the background using exuberant-ctags.
This way you can jump to classes (even Androids source files) simply by
pressing CTRL-]
.
:GrandInstall Installs your project on all connected devices (you'll still
have to manually start the app. It's in the TODO list).
To have the plugin know what dependencies you have in your project, add this
line to your build.gradle
file:
apply from: 'https://raw.githubusercontent.com/meonlol/vim-grand/master/grand.gradle'
When you now call ./gradlew outputPaths
on the commandline, a text file is
generated containing gradle's paths. Every time GrandSetup
is called, this
file is parsed for new paths. So if you change a dependency in build.gradle
run the 'outputPaths' command again and vim-grand will know about it.
If javacomplete gets slow, it might have to many paths to search. Open the
.grand_source_paths
file and customize what paths are to be used where,
according to the following rules:
- some/path # Path is ignored
c some/other/path # Used for completion javacomplete only
s some/jar.jar # Used for syntastic only
+ some/sources # Used everywhere
These tweaks and mappings for in you .vimrc will make you happy.
"Run GrandCtags command every time you save a java file
autocmd BufWritePost *.java silent! GrandCtags
"Use vim-dispatch to run gradleTest when you press <leader>ua
autocmd FileType java nnoremap <leader>ua :w<bar>Dispatch gradle test -q<CR>
The formatting of the gradles test output is really messy. I'll try and improve this soon, but in the mean time, you can use this gist to make it look acceptable.
Don't want to run all the tests every time? The robolectric plugin does not
support that yet. You can add this little
gist to your
build.gradle under robolectric {}
. Then you can call gradle test -q -Dclasses=AwesomeTestClass
from the commandline, or you could use this mapping
from vim:
"This runs the robolectric test for the current buffer with <leader>uc
autocmd FileType java nnoremap <leader>uc :w<bar>Dispatch gradle test -q -Dclasses=%:t:r<CR>
- Some refactoring (project not clean)
- add vimdocs
- GradleInstall should also launch app
- Integrated testing with jumpable test results
- build using Dispatch
- parse test-result xml to build quickfix
Please do! You know the drill. Just issue and pull.
Copyright (c) Leon Moll. Distributed under the same terms as Vim itself.
See :help license
.