Hi Guys
I have a problem with Spring integration developing a TeamCity plugin.

I'm using IntelliJ 12 Ultimate (build 123.139) and developing TeamCity plugin. I'm using Spring librabry that comes packed with TeamCity 7.1.3. (the one in TeamCity\webapps\ROOT\WEB-INF\lib). The librabry spring.jar is set as my dependency (in Project Structure -> Modules -> Dependencies) along with spring-webmvc.jar. When I'm trying to build the project I get this error:

java: C:\Dev\Projects\blahblah\src\main\java\foo\bar\FooBarController.java:13: cannot access org.springframework.beans.factory.Aware

The class org.springframework.beans.factory.Aware appears since Spring 3.x. The spring.jar that is bundled in TeamCity is old Spring 2.5.x and the only thing it has is BeanFactoryAware.

Something is not right and I cannot put a finger on it.
My FooBarController.java looks like this:

package foo.bar;

import jetbrains.buildServer.controllers.BaseController;
import jetbrains.buildServer.web.openapi.WebControllerManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.nio.charset.Charset;

public class FooBarController extends BaseController {

public FooBarController (WebControllerManager webControllerManager) {
logger.info("Registering new controller at URL");
webControllerManager.registerController(SYNC_CONTROLLER, this);
}

@Nullable
protected ModelAndView doHandle(@NotNull HttpServletRequest httpServletRequest, @NotNull HttpServletResponse httpServletResponse) throws Exception {
httpServletResponse.setStatus(HttpServletResponse.SC_OK);
httpServletResponse.setContentType("text/plain");
httpServletResponse.setCharacterEncoding("UTF-8");
httpServletResponse.getOutputStream().write("OK".getBytes(Charset.forName("UTF-8")));
return null;
}
}

Any help would be appriciated.

Greg

Could you zip and put online your project some place? This will be the easiest way to diagnose the cause. Thanks.

Hi Yann
I've zipped the project and attached to this post.

You will need Gradle 1.x, Java 1.6 and TeamCity (ideally the same that I have TC 7.1.3) on your machine to be able to set it up.

Instructions on setting it up:

• Unzip the files.
• Edit build.gradle file: set teamCityDistribution and  teamCityDataDir to your local TeamCity location. Setup repository (if you don't have local maven repo use mavenCentral(), like this:

repositories {

mavenCentral()

}

• From the command line run gradle idea . You should see output like this:

:ideaModule
:ideaProject
:ideaWorkspace
:idea

BUILD SUCCESSFUL

Enjoy your *.ipr file with IntelliJ.
It is possible you'll have to setup project level SDK once opened in IntelliJ.

Let me know if that works and how I can fix the issue.

Cheers, Greg

Attachment(s):
teamcity-crowd-integration.zip

I followed your steps but got stuck with some issues yet, so here's a couple of questions first:

- servlet-api.jar should not be in compile, but provided scope
- https://getsatisfaction.com/sonatype/topics/invalid_version_in_xmlschema_1_1_pom_xml XmlSchema 1.1 seems completely broken, for Atlassian stuff have to add Maven repo https://maven.atlassian.com/repository/public
- why do you generate "gradle idea" project files? did you try importing the build.gradle and let JetGradle plugin create/sync IDEA project from there?

Maybe other plugin authors shared their experience/setup with Gradle in TeamCity forum: http://devnet.jetbrains.com/community/teamcity ? Just a suggestion.

Hi Yann
It seems that IntelliJ Spring Integration plugin tries to use Spring 3.x despite the fact that dependency is for 2.5.6.
It also makes no difference if I use JetGradle plugin integration. Same issue.

What I was able to do is this:

• Follow the steps described by me in the previous post.
• Open the project, setup SDK.
• Try to compile, it will fail.
• Add Spring as a library. Point to a file from dependency (same as gradle).
• Try to compile. Still fails.
• Now, in Project Structure -> Libraries -> Spring a Change Version button appeared.
• Choose version 2.5.6 and move the Library on higher on a list of dependencies in Project Structure -> Modules -> Dependencies
• Now, Compile works!

Once the IDEA project and modules files are generated by Gradle when I start IntelliJ it detects Spring files. There is a way to configure which xml files to take, but it never asks about Spring version or which Spring jars to use.

Greg

Spring plugin will use whatever Spring library version is configured in your project, unless you tell it to download and create a new Spring library. Could you please double-check your Libraries in Project Structure and dependencies in your module for such duplicate Spring library?

When you generate with gradle idea, the only spring entries that are there are in *.iml file. Those are pointing to Spring in TeamCity distribution (which is 2.5.x).

<orderEntry type="module-library" exported="">
<library>
<CLASSES>
<root url="jar://$TeamCityDistribution$/webapps/ROOT/WEB-INF/lib/spring.jar!/" />
</CLASSES>
<SOURCES />
</library>
</orderEntry>

Once you open the project in IntelliJ the only new entry that appears is:

<component name="FacetManager">
<facet type="Spring" name="Spring">
<configuration>
<fileset id="fileset1" name="XML Application Context" removed="false">
<file>file://$MODULE_DIR$/src/test/resources/test-build-server-plugin-TeamCityCrowdIntegration.xml</file>
<file>file://$MODULE_DIR$/src/main/resources/build-server-plugin-TeamCityCrowdIntegration.xml</file>
<file>file://$MODULE_DIR$/src/spring-config.xml</file>
</fileset>
</configuration>
</facet>
</component>

Nothing else other than MODULE dependency is configured for Spring.

It looks like $TeamCityDistribution$/webapps/ROOT/WEB-INF/lib/spring.jar is ignored and IntelliJ falls into using whatever Spring version is default.
Greg

Ok, both config files look good indeed. Since I can't get your gradle build running here completely I can only second-guess, but is there a chance that from some other jar another Spring library is referenced or even re-packaged? IDEA will never attempt to use some default or create any such library unless told to do so, so it must be configured in your project somehow.

There is no other Spring references or repackeged classes. Also, there is no more traces of Spring config other than the one I posted in previouspost.

Let me know what Gradle stuff is not working for you?

Greg

This might be the underlying cause:
https://maven.atlassian.com/content/groups/public/com/atlassian/crowd/atlassian-crowd/2.5.3/atlassian-crowd-2.5.3.pom

From the POM it looks like Atlassian Crowd has a dependency to Spring Framework 3.1.2

Hm ...
It could be, however, generated *.iml file doesn't reference this version of Spring anywhere :/
Greg

I'm not familiar with gradle:idea target, but I'd guess it does not include/show transitive dependencies. So I guess this issue is now resolved (at least from a what-caused-this perspective)?

Hi Yann
Thanks for still trying to nail it.
I've attached the 3 files generated by gradle idea target.
There is no transitive dependencies for Spring 3.x. Have a look yourself.
Greg

Attachment(s):
intellij-files.zip

What I meant was the transitive dependency on Spring 3 comes from the fact that your code references crowd-classes which in turn need Spring 3.x in classpath to compile.The fact the gradle:idea does not resolve/include those dependencies is another issue.
At least that's what I think happens in your project (still can't get it up and running here).

The error I got when trying to import your project (http://youtrack.jetbrains.com/issue/IDEA-100968) is fixed in 12.1. Please try upcoming EAP.

Hi Yann
Thank you :)
Greg