Building IntelliJ project in TeamCity - java

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:
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.
At the build configuration level, set the system.path.macro.MAVEN.REPOSITORY system property to %env.HOME%/.m2/repository.
That's it.
Happy building!

Related

Accessing a built in intelij plugin from another plugin

I'm writing an InteliJ plugin, and one of the things it is required to do is add a maven dependency to a project if it doesn't exist already. I've found a unit test in InteliJ that does what I want to do, which serves as an example, but I can't figure out how to access the org.jetbrains.idea.maven.dom in my project.
I tried following the instructions here, and that meant that auto-complete etc. worked and I was able to write the code, but when I tried to compile it, I got:
error: package org.jetbrains.idea.maven.dom does not exist
import org.jetbrains.idea.maven.dom.MavenDomUtil;
Please declare dependency on Maven plugin as described here http://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_dependencies.html

QueryDsl error. Q classes not generated

I try to generate query type classes (e.g. QUser) but got errors...
You can find my source code here: https://github.com/TheNakedMan/remindme.server/
I'am working with IntelliJ IDEA, and it seems like I have working plugin.
Help me, please.
Log message:
/remindme.server/src/main/java/com/qoobico/remindme/server/repository/UserRepository.java
Error:(21, 126) java: cannot find symbol symbol: class QUser
Error:(25, 62) java: cannot find symbol symbol: class QUser
location: interface
com.qoobico.remindme.server.repository.UserRepository
UPDATE:
After LifeCycle->clean and run apt:process in IntelliJ, I have this error:
[ERROR] Failed to execute goal on project com.qoobico.remindme.server:
Could not resolve dependencies for project
com.qoobico.remindme.server:com.qoobico.remindme.server:war:1.0-SNAPSHOT:
Could not find artifact
com.qoobico.remindme.server:com.qoobico.remindme.server:jar:1.0-SNAPSHOT
In your sources you did not import the generated classes, for instance:
import com.qoobico.remindme.server.entity.QUser;
If you want to generate the classes without compile and/or install the package use the maven goal apt:process.
You can use IntelliJ to start such a maven goal, use the Maven Projects window. The window will show you all available goals.
On the commandline you could use the mvn cli, which can be downloaded here.
Hint: the command from the help plugin mvn help:describe -Dplugin=com.mysema.maven:apt-maven-plugin will show you a list of all available apt-maven-plugin goals.
You configured the outputDirectory to: target/generated-sources/java
To let your IDE find that classes, put them into your class path. Some IDEs like IntelliJ will do this automatically for maven projects, because that folder is the default.

How do I get IntelliJ to recognise resource bundle when compiling?

Ok, first up I am almost completely unfamiliar with Java and Java tooling.
I am attempting to contribute a bugfix to a Jenkins plugin. Code-wise the fix is simple, my problem is in trying to compile the project and run the tests locally.
I have installed IntelliJ IDEA 15CE and started a new project, pointing it to my local clone of the plugin repo.
It has gone away and 'downloaded the internet' in terms of Maven dependencies. Mostly everything looks ok. What I want to do is to run the tests...
If I right-click at the root of the project and select 'Run All Tests' I get the error:
Error:(115, 29) java: cannot find symbol
symbol: variable Messages
location: class hudson.plugins.copyartifact.BuildSelector
The source of this error is a line:
console.println(Messages.CopyArtifact_MissingSrcArtifacts(srcDir));
https://github.com/jenkinsci/copyartifact-plugin/blob/master/src/main/java/hudson/plugins/copyartifact/BuildSelector.java#L115
As far as I can tell the Messages symbol should resolve to this properties file:
https://github.com/jenkinsci/copyartifact-plugin/blob/master/src/main/resources/hudson/plugins/copyartifact/Messages.properties
...which IDEA recognises as a 'Resource Bundle' in the project tree view.
But it doesn't seem to recognise it when compiling the project.
I have no idea where to start fixing this. The tests run fine if I push a commit to a pull request on GitHub and let the cloudbees.com Jenkins server run them, but I'd like to be able to test stuff locally first.
Run the maven compile command from Intelli-J Maven tool. After compiling error will vanish.
When you compile it will generate a Messages.java file in generated sources automatically.

Maven: package does not exist

I was developing an application like ordinary Java Web application, but because I want to deploy it to Heroku, I needed it to become Maven project, so I created an empty Maven project with Eclipse and copied all of libraries I was using and all of my source code.
When I do mvn compile on my local machine, it goes well, but app isn't really working.
When I do git push heroku master I get error like
package com.mysite.java.classes does not exist
Locally I have maven-compiler-plugin ver 3.1 and source and target set to 1.7, although I'm using 1.8 jdk. I changed it to 1.7 since I saw here Pushing my repository to heroku fails that it has issues with Heroku.
Here is a project structure
I'm not really experienced with Maven, so I hope somebody can help. I guess imports aren't working as intended because I get whole list of errors like this
symbol: class Connection
location: class com.vukstankovic.professionalorientation.Personalities
[ERROR] /tmp/build_0bc5a80c-dc14-4126-b15b-69390f18dc9f/src/main/java/com/vukstankovic/professionalorientation/Personalities.java:[48,19] cannot find symbol
Class Connection in this example is mysql class from com.mysql.jdbc.Connection

springframework source in Idea Intellij

I'm having hard time to setup springframework code in Intellij.
I git-cloned springframework project from github, and ran ant task to get all the libraries into ivy-cache directory.
I found "spring-framework.ipr" file for intellij project, and opened it.
Unfortunately, some of the libraries are not correctly mapped to the jar files or missing. So I cannot compile the codebase in IDE.
I also tried importing as eclipse project into intellij. Jar file reference seems ok.
But there are compilation errors in OXM module. Some test classes have reference to auto generated classes such as "~.samples.flight.FlightDocument", "~.jaxb.test.FlightType", and they don't exist(ant test goal generates them in target dir).
It seems same problem happens in STS.
I referenced this blog post:
http://blog.springsource.org/2009/03/03/building-spring-3/
Any good idea to setup spring code in intellij?
I use intellij v11.
git branch: 3.1.x
git commit: e8fc90ce3e4554f14eaa86ce05591249d3fe62fa
Compilation error example:
.../org.springframework.oxm/src/test/java/org/springframework/oxm/xmlbeans/XmlBeansMarshaller Tests.java
Error:(29,42) package org.springframework.samples.flight does not exist
Error:(30,42) package org.springframework.samples.flight does not exist
Error:(44,9) cannot find symbol class FlightsDocument
Error:(44,58) package FlightsDocument does not exist
....
Thanks,
problem solved.
"spring-framework.ipr" is the one for intellij.
lesson learned:
simply wrong version of junit was referenced in spring-framework.ipr file.
when ant build failed middle of the test, subsequent module won't be built. so, required libraries won't be downloaded into ivy-cache/repository.
"ant jar" goal will not download test related libraries since the goal doesn't run tests
After all the tests passed and manually fixed junit reference, intellij finally has no errors.

Categories