intellij workable?

491 views
Skip to first unread message

P. Oscar Boykin

unread,
Feb 5, 2016, 8:14:41 PM2/5/16
to bazel-discuss
I don't use intellij, but many of my colleagues do.


Anyone using it happily? I heard braintree had their own script around intellij. I'm a bit nervous to oversell how happy my colleagues will be with that. Any additional info would be great.

Thanks.

Thiago Farina

unread,
Feb 8, 2016, 12:43:43 PM2/8/16
to P. Oscar Boykin, bazel-discuss


On Saturday, February 6, 2016, P. Oscar Boykin <oscar....@gmail.com> wrote:
I don't use intellij, but many of my colleagues do.

It was last time I tried it.
 


--
Thiago Farina

Erik Kuefler

unread,
Feb 9, 2016, 3:53:35 AM2/9/16
to bazel-discuss
I haven't actually tried the script, but my team has been using Bazel+IntelliJ for months now just by keeping a build.gradle file that does nothing but mirror the dependencies in our WORKSPACE, and driving IntelliJ off of that. That's probably not the best way to do it, but it's been working surprisingly well enough that I haven't looked into alternatives. So that's a possible fallback if the script gives you trouble.

Paul Gross

unread,
Feb 12, 2016, 1:47:57 AM2/12/16
to Erik Kuefler, bazel-discuss
We used that script as inspiration, but wound up writing our own script. It's been about 6 months, so my info may be out of date, but our main reasons were:

- We ported a gradle project with submodules, so we wanted a maven/gradle style intellij project complete with submodules that depend on other submodules (all inferred from bazel query).
- We wanted to customize the templates with our own intellij settings.
- We wanted our intellij project to include some extra bazel generated content, which we include from bazel-genfiles.
- The bazel script pulled in ijars instead of the real external jars, which meant you couldn't run the tests from intellij

Overall, it wasn't too hard to write our script. And when we want to make changes, often the easiest thing to do is make the changes in the intellij UI, inspect the difference in generated iml or idea files, and then copy those to our templates.

One big difference from using the maven or gradle plugin is that your intellij configuration is static. If you change your BUILD files, you have to regenerate your intellij project. On the one hand, we found it made intellij more stable than the gradle plugin which would try to refresh and often wind up in a bad state where it couldn't compile. On the other hand, if you make a big bazel/java change and haven't gotten "bazel build" working yet, you can't fix the errors in intellij since you can't generate the project. There have been a few times where I had to fix java compilation errors in another editor until I could get bazel working enough to regenerate the project.

Also, this script (and ours) sets up dependencies on the generated protobuf jars. This means if you change your protos, you have to bounce intellij since it won't pick up changes to jars. Also, intellij won't let you add the bazel generated srcjars as source jars. I've tried a few things to work around these two issues, but haven't had much luck (partially due to the fact that we ignore most of the bazel-* directories in intellij to reduce noise).

Overall, we have a decently sized team using our script and working in intellij daily. It's not painless, but it's also not too bad.

Hope this helps,
Paul

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/c1af965c-96ae-4fff-a345-830637fb8fca%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

micke...@gmail.com

unread,
Feb 12, 2016, 7:36:41 PM2/12/16
to bazel-discuss, ekue...@gmail.com
On Thursday, February 11, 2016 at 10:47:57 PM UTC-8, Paul Gross wrote:
> We used that script as inspiration, but wound up writing our own script. It's been about 6 months, so my info may be out of date, but our main reasons were:
>

We are using a similar solution to Paul on my team. We also forked the official script from the bazel repository (https://github.com/bazelbuild/bazel/blob/master/scripts/setup-intellij.sh). Ours hacky script is posted below.

We are finding this solution workable but suboptimal. The main issue is that work needs to be manually mirrored in both bazel and IntelliJ (e.g. jvm_flags, working directories, generated sources).

We would love to see the development of an IntelliJ plugin. Based on these docs (http://www.jetbrains.org/intellij/sdk/docs/index.html), it seems possible. I also do see that a plugin has been development for facebook's similar tool, buck (https://github.com/wangyanxing/Buck-IntelliJ-Plugin).

Is anyone else interested in collaborating on such a plugin?

---

scripts/setup_intellij.sh (slightly redacted)

#!/bin/bash
# Copyright 2015 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Generates an IntelliJ project in Bazel.

set -o errexit
cd $(dirname "$0")
cd ..

bazel build //...

echo "Generating a bunch of xml files for intellij...very, very slowly :("

mkdir -p .idea/
# these directories contain manually managed .idea xml files, including shared runConfigurations, compiler.xml, encodings.xml, misc.xml and vcs.xml
cp -R scripts/resources/idea/* .idea/
cp -R scripts/resources/idea/*.* .idea/
cp -R scripts/resources/idea/.* .idea/

readonly compiler_file=.idea/compiler.xml
cat >$compiler_file <<'EOH'
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<excludeFromCompile>
EOH
cat >>$compiler_file <<'EOF'
</excludeFromCompile>
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
<entry name="!?*.aj" />
</wildcardResourcePatterns>
</component>
</project>
EOF

mkdir -p .idea/libraries
for jar in $(find -L bazel-bin -name '*.jar' | grep external); do
jarname=$(basename $jar)
library_xml=".idea/libraries/${jarname%.*}.xml"
cat > $library_xml <<EOF
<component name="libraryTable">
<library name="${jarname%.*}">
<CLASSES>
<root url="jar://\$PROJECT_DIR$/$jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
EOF
done

cat > projectname.iml <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<content url="file://\$MODULE_DIR$">
<excludeFolder url="file://\$MODULE_DIR$/bazel-bin" />
<excludeFolder url="file://\$MODULE_DIR$/bazel-genfiles/external" />
<excludeFolder url="file://\$MODULE_DIR$/bazel-<projectname>-java" />
<excludeFolder url="file://\$MODULE_DIR$/bazel-out" />
<excludeFolder url="file://\$MODULE_DIR$/bazel-testlogs" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
EOF

# Start modules.xml
cat > .idea/modules.xml <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://\$PROJECT_DIR\$/<projectname>.iml" filepath="\$PROJECT_DIR\$/bazel.iml" />
EOF

# Note: these module names are managed manually
for module in <module names>; do
module_iml="${module}/${module}.iml"
cat > $module_iml <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<content url="file://\$MODULE_DIR$">
EOF
[[ -d $module/src/main/java ]] && cat >> $module_iml <<EOF
<sourceFolder url="file://\$MODULE_DIR$/src/main/java" isTestSource="false" />
EOF
[[ -d $module/src/test/java ]] && cat >> $module_iml <<EOF
<sourceFolder url="file://\$MODULE_DIR$/src/test/java" isTestSource="true" />
EOF
[[ -d $module/src/jooq/java ]] && cat >> $module_iml <<EOF
<sourceFolder url="file://\$MODULE_DIR$/src/jooq/java" isTestSource="false" />
EOF
[[ -d $module/src/main/resources ]] && cat >> $module_iml <<EOF
<sourceFolder url="file://\$MODULE_DIR$/src/main/resources" type="java-resource" />
EOF
[[ -d $module/src/test/resources ]] && cat >> $module_iml <<EOF
<sourceFolder url="file://\$MODULE_DIR$/src/test/resources" type="java-test-resource "/>
EOF
cat >> $module_iml <<EOF
</content>
EOF
if [[ -d bazel-genfiles/$module/src/main/java ]]; then
cat >> $module_iml <<EOF
<content url="file://\$MODULE_DIR$/../bazel-genfiles/$module">
<sourceFolder url="file://\$MODULE_DIR$/../bazel-genfiles/protos/src/main/java" isTestSource="false" generated="true" />
</content>
EOF
fi

cat >> $module_iml <<EOF
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
EOF

for module_dependency in $(bazel query "kind(\"java_library\", deps(//$module)) - //third-party:*" 2> /dev/null | cut -f2 -d:); do
cat >> $module_iml <<EOF
<orderEntry type="module" module-name="$module_dependency" />
EOF
done

for dependency in $(find -L bazel-bin -name '*.jar' | grep external); do
jarname=$(basename $dependency)
cat >> $module_iml <<EOF
<orderEntry type="library" name="${jarname%.*}" level="project" />
EOF
done

cat >> $module_iml <<EOF
</component>
</module>
EOF

cat >> .idea/modules.xml <<EOF
<module fileurl="file://\$PROJECT_DIR\$/$module/$module.iml" filepath="\$PROJECT_DIR\$/$module/$module.iml" />
EOF
done


# Finish modules.xml
cat >> .idea/modules.xml <<EOF
</modules>
</component>
</project>
EOF

Ulf Adams

unread,
Feb 16, 2016, 3:53:02 AM2/16/16
to micke...@gmail.com, bazel-discuss, Erik Kuefler
Hi all,

in the interest of full disclosure: we have some code internally for integrating with IntelliJ and AndroidStudio, which we'd love to open source. Unfortunately, there are three problems - 1) the code is still somewhat experimental, 2) we are sort of afraid that we'll get a lot of bug reports which we will be unable to handle, and 3) there's a fundamental mismatch between IntelliJ's build model and Bazel's model, which means that a lot of code cannot be imported, which feeds into 2.

Note that the Bazel side is open source already, so anyone could reproduce / work on this if they wanted to, and we're hoping to be able to support other IDEs in a similar way as well. We're working on a blog post that explains how the Bazel-side functionality works.

Unfortunately, I can't even give a timeline for when this might happen. We're all trying to push this forward, but it will be some time before we can get there.

Sorry,

-- Ulf

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.

Doug Tangren

unread,
May 22, 2017, 6:29:11 PM5/22/17
to bazel-discuss, ekue...@gmail.com


On Friday, February 12, 2016 at 1:47:57 AM UTC-5, Paul Gross wrote:
 
Also, intellij won't let you add the bazel generated srcjars as source jars. I've tried a few things to work around these two issues, but haven't had much luck (partially due to the fact that we ignore most of the bazel-* directories in intellij to reduce noise).


Has anyone here overcame the srcjar mapping issue with intellij? We're trying to set up intellij to provide it with knowledge of generated source files  but are stuck on it's inability to read from .srcjar files. The alternative would be to name these files with a .jar extension but then the various rules that reference typically depend on their file extension to know what kind of jars they are.

ittai zeidman

unread,
May 23, 2017, 12:23:19 AM5/23/17
to bazel-discuss
Does this work in the official plugin?

Doug Tangren

unread,
May 23, 2017, 1:16:50 AM5/23/17
to ittai zeidman, bazel-discuss


On May 23, 2017 12:23 AM, "ittai zeidman" <itt...@gmail.com> wrote:
Does this work in the official plugin?

I'd like to know as well. I don't use intellij myself by my coworkers will definitely want access to generated sources. We're not really looking for a gui to run bazel actions atm.


--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/3ab23883-46fd-43f3-b363-75e2fbcaa0e4%40googlegroups.com.

John Field

unread,
May 23, 2017, 11:37:13 AM5/23/17
to Doug Tangren, ittai zeidman, brendan...@google.com, bazel-discuss

On Tue, May 23, 2017 at 1:16 AM Doug Tangren <d.ta...@gmail.com> wrote:


On May 23, 2017 12:23 AM, "ittai zeidman" <itt...@gmail.com> wrote:
Does this work in the official plugin?

I'd like to know as well. I don't use intellij myself by my coworkers will definitely want access to generated sources. We're not really looking for a gui to run bazel actions atm.

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/CAJ2WPXhGbDY0ymLj4z7ELG7g42borQ84MUKOEqa2Pm-Cb4nZqQ%40mail.gmail.com.

brendan...@google.com

unread,
May 23, 2017, 12:29:15 PM5/23/17
to bazel-discuss, d.ta...@gmail.com, itt...@gmail.com, brendan...@google.com
> Does this work in the official plugin?

It certainly should. If there are any issues, we have a separate bug tracker for the IntelliJ Bazel plugin at: https://github.com/bazelbuild/intellij/issues

Reply all
Reply to author
Forward
0 new messages