1

I'm new to IntelliJ and Java but I have a fair bit of TeamCity experience, mostly building .Net projects.

I have created a very simple Android Library project in IntelliJ with basically a single class that uses RxJava (Reactive Extensions for Java). I have added the Rx library in IntelliJ using Project Structure -> Libraries -> From Maven. The actual library I have added is com.netflix.rxjava:rxjava-android:0.19.6 which pulls in com.netflix.rxjava:rxjava-core:0.19.6.

This works brilliantly and my project compiles within IntelliJ without even having to install Maven. Nice job, JetBrains.

However, when I try to build the project in TeamCity using the IntelliJ-IDEA runner, the project doesn't compile. Bad JetBrains!

I get errors on all the references to rx.*, which as I said all worked perfectly on my workstation. The errors from TeamCity look like this:

C:\BuildAgent\work\eefd62e2c3082b56\src\com\example\TigraAndroidUtilities\ObservableModel.java:3: package rx does not exist  
import rx.Observable;  
         ^  
C:\BuildAgent\work\eefd62e2c3082b56\src\com\example\TigraAndroidUtilities\ObservableModel.java:4:   package rx.subjects does not exist  
import rx.subjects.BehaviorSubject;  
                  ^  
C:\BuildAgent\work\eefd62e2c3082b56\src\com\example\TigraAndroidUtilities\ObservableModel.java:18:   cannot find symbol  
  symbol:   class BehaviorSubject  
  location: class com.example.TigraAndroidUtilities.ObservableModel  
    private BehaviorSubject modelStream;  
            ^  
C:\BuildAgent\work\eefd62e2c3082b56\src\com\example\TigraAndroidUtilities\ObservableModel.java:63:   cannot find symbol  
  symbol:   class Observable  
  location: class com.example.TigraAndroidUtilities.ObservableModel  
    public Observable toObservable()  
           ^  
C:\BuildAgent\work\eefd62e2c3082b56\src\com\example\TigraAndroidUtilities\ObservableModel.java:28:   cannot find symbol  
  symbol:   variable BehaviorSubject  
  location: class com.example.TigraAndroidUtilities.ObservableModel  
        modelStream = BehaviorSubject.create(modelData);  
                      ^  
C:\BuildAgent\work\eefd62e2c3082b56\src\com\example\TigraAndroidUtilities\ObservableModel.java:65:   cannot find symbol  
  symbol:   variable Observable  
  location: class com.example.TigraAndroidUtilities.ObservableModel  
        if (completed) { return Observable.empty(); } 
                                ^   

Here's what I've tried:

  • Considered using the Maven build runner instead; but the project doesn't have a POM file so it's not a Maven build.
  • I've tried installing Maven on the build agent, that doesn't seem to make any difference and I didn't need to install it for IntelliJ to work locally so I can't see why it would be needed.
  • There is a path macro called MAVEN_REPOSITORY in the IntelliJ build runner settings and I've tried setting that to various different values, no luck.
  • I've looked at JetBrains' documentation for the IntelliJ runner and as far as I can tell, I've configured my build step correctly. Clearly I'm missing something though.

This is all a bit frustrating, I've been tinkering with it hours but nothing seems to work and basically I have no clue what I'm doing wrong. I must have missed something somewhere. How can I get this build working properly in TeamCity?

Tim Long
  • 13,508
  • 19
  • 79
  • 147
  • 1
    I'm a bit rusty on TeamCity (since using Bamboo/hosted CI) but have you tried using a maven runner with a POM anyways? Also, why are you importing a maven library but not adding it in the POM? –  Aug 19 '14 at 02:28
  • @xTrollxDudex there is no POM; it's not a Maven build. IntelliJ has its own built-in Maven integration that lets you add libraries from the Maven central repository, directly in IntelliJ, for a self-contained project and build system, which is one of the reasons I find it attractive. I was hoping that the two JetBrains products might integrate better than they seem to be doing in practice. TeamCity has an IntelliJ build runner that is supposed to build IntelliJ projects - I have an IntelliJ project and its not building. Perhaps I'm kidding myself but I was hoping that would work. – Tim Long Aug 19 '14 at 03:49
  • 1
    Not sure if you are running teamcity on a host behind a firewall which might be blocking your Rx* related artefact downloads. Intellij projects do build out of the box for teamcity if we have all our required libraries on our dependency servers instead of outside our firewall – Biswajit_86 Aug 19 '14 at 04:36
  • @Biswajit_86 I don't think it is a firewall issue, but you may be on to something there. The project is trying to build; it just can't find any of the libraries. I'm thinking that I either have to commit them into VCS somehow, how preinstall them on the build agent. How do you get your dependencies onto the build server? – Tim Long Aug 19 '14 at 12:06
  • We have explicit dependencies. So we declare all our dependencies in a a target and fetch them before we run any builds.we add this folder to our library – Biswajit_86 Aug 20 '14 at 02:48
  • Did you manage to get this to work? – mcintyre321 Apr 02 '15 at 11:28
  • @mcintyre321 I have since got a very simple 'vanilla' project to build, but I never solved the above. – Tim Long Apr 03 '15 at 17:20
  • We've just worked around this by using an explicit maven build command. I feel like TeamCity is missing an 'Auto-Import' checkbox like IntelliJ has... – mcintyre321 Apr 05 '15 at 16:39

1 Answers1

1

As of TeamCity 9.1, its IDEA runner can't build Maven modules any longer, nor can it auto-download external artifacts from Maven Central.

Basically, what you need is:

  1. Download external artifacts, one by one, using TeamCity Maven runner and maven-dependency-plugin, as described in this answer., e. g.:

    mvn org.apache.maven.plugins:maven-dependency-plugin:3.0.0:get com.netflix.rxjava:rxjava-android:0.19.6
    

    You'll need as many Maven build steps as the number of dependencies in your IDEA project, and these steps must precede the IDEA runner build step.

  2. At the build configuration level, set the system.path.macro.MAVEN.REPOSITORY system property to %env.HOME%/.m2/repository.

That's it.

Happy building!

Community
  • 1
  • 1
Bass
  • 4,977
  • 2
  • 36
  • 82