0

I'm configuring a TeamCity 2018.1 instance using Kotlin portable DSL. When I exported the DSL from the TeamCity web UI, my project structure looked like this:

<Root>
|- Project A
|- Project B

This gave me a file system structure that looked something like this:

.teamcity
|- _Self
   |- project.kts
|- Project A
   |- project.kts
|- Project B
   |- project.kts
|- settings.kts

Currently, there are static references when loading subprojects, similar to this

import Project_A.*
// …
subProject(Project_A.Project)
subProject(Project_B.Project)

I want to modify the Root settings.kts file so that I could load projects dynamically. I'm trying this:

version = "2018.1"
project {
    subProject {
        id("Root")
        name = "Root"
        for(project in arrayListOf("Project_A.Project", "Project_B.Project")) {
            val subProj = Class.forName("$project").getConstructor().newInstance() as Project
            subProject(subProj)
        }
    }
}

However, this fails with:

_Root: java.net.URLClassLoader [381]:                  
              java.lang.ClassNotFoundException: Project_A

Why does it fail?

codekaizen
  • 26,990
  • 7
  • 84
  • 140

1 Answers1

1

Another option instead of calling subProject() is to create settings.kts file in each subproject directory.

you can find this comment in you current settings.kts:

Subprojects can be defined either in their own settings.kts or by calling the subProjects() method in this project.

I'm not sure why you want to do this "dynamically". Your example have hardcoded names.

If you really need from some reason to create a subproject relation dynamically you can create those .kts files dynamically

Piotr Boho
  • 2,650
  • 2
  • 13
  • 20
  • Thanks for the insight, I was wondering about this exact possibility. Do you know if this is documented somewhere? – codekaizen Sep 10 '18 at 22:55
  • Hej Piotr - where did you see "Subprojects can be defined either in their own settings.kts or by calling the subProjects() method in this project." .. I have tried doing this (version 2019.1), but get the message: ... "The mix of top-level and project-level settings scripts is not supported. To proceed, remove the project-level scripts:" etc .. – OneMoreNerd Jul 20 '20 at 17:47