简体   繁体   中英

Building IntelliJ project in TeamCity

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?

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., eg:

     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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM