rodm/gradle-teamcity-plugin

TeamCity API test dependency version not respected

Closed this issue · 2 comments

Hi there,
Consider the following simple plugin with agent & server parts (and some shared logic in buildSrc). It has a plugin configuration for the agent part

teamcity {
    version = "2022.12-SNAPSHOT"
    allowSnapshotVersions = true
}

After migration to the latest version of new packages

id "io.github.rodm.teamcity-server" version "1.5"
id "io.github.rodm.teamcity-agent" version "1.5"

There is an issue with the version of the TeamCity API to build against in tests. For instance, If you run:

./gradlew :agent:dependencies --configuration testCompileClasspath

You get the following

testCompileClasspath - Compile classpath for compilation 'test' (target  (jvm)).
+--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.7.20
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.7.20
|    |    \--- org.jetbrains:annotations:13.0
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.20
|         \--- org.jetbrains.kotlin:kotlin-stdlib:1.7.20 (*)
+--- org.jetbrains.teamcity:agent-api:2022.12-SNAPSHOT
|    +--- org.jetbrains.teamcity:common-api:2022.12-SNAPSHOT
|    |    +--- com.google.code.findbugs:jsr305:3.0.2
|    |    +--- com.google.code.gson:gson:2.9.0
|    |    +--- com.google.guava:failureaccess:1.0.1
|    |    +--- com.google.guava:guava:31.1-android
|    |    |    +--- com.google.guava:failureaccess:1.0.1
|    |    |    +--- com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
|    |    |    +--- com.google.code.findbugs:jsr305:3.0.2
|    |    |    +--- org.checkerframework:checker-qual:3.12.0
|    |    |    +--- com.google.errorprone:error_prone_annotations:2.11.0
|    |    |    \--- com.google.j2objc:j2objc-annotations:1.3
|    |    +--- commons-codec:commons-codec:1.11
|    |    +--- commons-httpclient:commons-httpclient:3.1
|    |    |    +--- commons-logging:commons-logging:1.0.4 -> 1.2
|    |    |    \--- commons-codec:commons-codec:1.2 -> 1.11
|    |    +--- commons-io:commons-io:1.3.2
|    |    +--- commons-logging:commons-logging:1.2
|    |    +--- dom4j:dom4j:1.6.1
|    |    |    \--- xml-apis:xml-apis:1.0.b2 -> 1.4.01
|    |    +--- jaxen:jaxen:1.1.1
|    |    |    +--- dom4j:dom4j:1.6.1 (*)
|    |    |    +--- jdom:jdom:1.0
|    |    |    +--- xml-apis:xml-apis:1.3.02 -> 1.4.01
|    |    |    +--- xerces:xercesImpl:2.6.2 -> 2.12.1
|    |    |    |    \--- xml-apis:xml-apis:1.4.01
|    |    |    \--- xom:xom:1.0 -> 1.3.7
|    |    |         +--- xerces:xercesImpl:2.8.0 -> 2.12.1 (*)
|    |    |         \--- xalan:xalan:2.7.2
|    |    |              \--- xalan:serializer:2.7.2
|    |    |                   \--- xml-apis:xml-apis:1.3.04 -> 1.4.01
|    |    +--- jdom:jdom:1.0
|    |    +--- joda-time:joda-time:2.5
|    |    +--- org.apache.commons:commons-compress:1.21
|    |    +--- org.apache.ws.xmlrpc:xmlrpc:2.0.1
|    |    |    +--- javax.servlet:servlet-api:2.2
|    |    |    +--- commons-codec:commons-codec:1.3 -> 1.11
|    |    |    \--- commons-httpclient:commons-httpclient:2.0.2 -> 3.1 (*)
|    |    +--- org.jetbrains:annotations:13.0
|    |    +--- org.jetbrains.teamcity:serviceMessages:2022.12-SNAPSHOT
|    |    +--- org.jetbrains.teamcity.idea:obsolete-openapi:2022.12-SNAPSHOT
|    |    |    +--- net.sf.trove4j:trove4j:3.0.3
|    |    |    +--- org.apache.logging.log4j:log4j-1.2-api:2.17.2
|    |    |    |    \--- org.apache.logging.log4j:log4j-api:2.17.2
|    |    |    +--- org.apache.logging.log4j:log4j-api:2.17.2
|    |    |    +--- org.apache.logging.log4j:log4j-core:2.17.2
|    |    |    |    \--- org.apache.logging.log4j:log4j-api:2.17.2
|    |    |    +--- org.jdom:jdom:1.1
|    |    |    \--- org.jetbrains.intellij.deps:trove4j:1.0.20181211
|    |    +--- org.jetbrains.teamcity.xstream:xstream:1.4.11.1
|    |    +--- org.tukaani:xz:1.8
|    |    +--- xalan:serializer:2.7.2 (*)
|    |    +--- xalan:xalan:2.7.2 (*)
|    |    +--- xerces:xercesImpl:2.12.1 (*)
|    |    +--- xml-apis:xml-apis:1.4.01
|    |    +--- xom:xom:1.3.7 (*)
|    |    \--- xpp3:xpp3:1.1.4c
|    +--- org.springframework:spring-aop:5.3.18
|    |    +--- org.springframework:spring-beans:5.3.18
|    |    |    \--- org.springframework:spring-core:5.3.18
|    |    |         \--- org.springframework:spring-jcl:5.3.18
|    |    \--- org.springframework:spring-core:5.3.18 (*)
|    +--- org.springframework:spring-aspects:5.3.18
|    |    \--- org.aspectj:aspectjweaver:1.9.7
|    +--- org.springframework:spring-beans:5.3.18 (*)
|    +--- org.springframework:spring-context:5.3.18
|    |    +--- org.springframework:spring-aop:5.3.18 (*)
|    |    +--- org.springframework:spring-beans:5.3.18 (*)
|    |    +--- org.springframework:spring-core:5.3.18 (*)
|    |    \--- org.springframework:spring-expression:5.3.18
|    |         \--- org.springframework:spring-core:5.3.18 (*)
|    +--- org.springframework:spring-context-support:5.3.18
|    |    +--- org.springframework:spring-beans:5.3.18 (*)
|    |    +--- org.springframework:spring-context:5.3.18 (*)
|    |    \--- org.springframework:spring-core:5.3.18 (*)
|    +--- org.springframework:spring-core:5.3.18 (*)
|    +--- org.springframework:spring-expression:5.3.18 (*)
|    +--- org.springframework:spring-instrument:5.3.18
|    +--- org.springframework:spring-jdbc:5.3.18
|    |    +--- org.springframework:spring-beans:5.3.18 (*)
|    |    +--- org.springframework:spring-core:5.3.18 (*)
|    |    \--- org.springframework:spring-tx:5.3.18
|    |         +--- org.springframework:spring-beans:5.3.18 (*)
|    |         \--- org.springframework:spring-core:5.3.18 (*)
|    \--- org.springframework:spring-tx:5.3.18 (*)
\--- org.jetbrains.teamcity:tests-support:9.0
     +--- jmock:jmock:1.2.0
     |    \--- junit:junit:3.8.1 -> 4.11
     |         \--- org.hamcrest:hamcrest-core:1.3
     +--- junit:junit:4.11 (*)
     +--- org.assertj:assertj-core:1.6.0
     +--- org.hamcrest:hamcrest-core:1.3
     +--- org.hamcrest:hamcrest-integration:1.3
     |    \--- org.hamcrest:hamcrest-library:1.3
     |         \--- org.hamcrest:hamcrest-core:1.3
     +--- org.hamcrest:hamcrest-library:1.3 (*)
     +--- org.jetbrains.teamcity:common-api:9.0 -> 2022.12-SNAPSHOT (*)
     +--- org.jmock:jmock:2.5.1
     |    +--- org.hamcrest:hamcrest-core:1.1 -> 1.3
     |    \--- org.hamcrest:hamcrest-library:1.1 -> 1.3 (*)
     +--- org.jmock:jmock-legacy:2.5.1
     |    +--- org.jmock:jmock:2.5.1 (*)
     |    +--- org.objenesis:objenesis:1.0
     |    \--- cglib:cglib-nodep:2.1_3
     +--- org.objenesis:objenesis:1.0
     \--- org.testng:testng:6.8
          +--- junit:junit:4.10 -> 4.11 (*)
          +--- org.beanshell:bsh:2.0b4
          +--- com.beust:jcommander:1.27
          \--- org.yaml:snakeyaml:1.6

You can see that almost all dependencies version is respected, but not for tests-support. It has a 9.0 version. It might break test compilation if some newer API is used and that version will be chosen by Gradle conflict resolution (the case with just the "SNAPSHOT" version).

One thing to note: if you change the order of the plugins, let's say instead of

plugins {
    id "io.github.rodm.teamcity-agent" version "1.5"
    id 'plugin-conventions'
}

You will use

plugins {
    id 'plugin-conventions'
    id "io.github.rodm.teamcity-agent" version "1.5"
}

Everything works as expected.

rodm commented

Using your example I can see the issue, however it looks like the problem is caused by the Kotlin JVM plugin. After adding some logging to the Gradle TeamCity plugin I can see that the configuration that the test-support dependency is added to is modified during Gradle's coniguration phase, this is why the default version, 9.0, is used. While version 1.4 of the Gradle TeamCity plugin appears correct it is hiding the problem, it configures the dependency using a means that is not recommended by the Gradle developers.

I would suggest you move applying the teamcity-agent plugin into a convention plugin script and ordering the plugins to avoid this problem.

I've just tried the latest available version of the Kotlin JVM plugin (1.8.0-RC) and it seems to work. Ok, thanks! I'm closing the issue