Itiviti / gradle-dotnet-plugin

Gradle plugin for interacting with dotnet cli
Apache License 2.0
19 stars 8 forks source link

Unclear 'namespace' for this plug in #29

Closed janzwanenburg closed 3 months ago

janzwanenburg commented 1 year ago

Hello, We have a large industrial C# repo (~5MLoC, 125 .sln files, 600 .csproj files). We would like to speed up the build of this repo significantly, by making it fully incremental. We are investigating whether Gradle would be a good solution for that. We don't have prior knowledge of Gradle, so I may be asking the obvious.

We have a sample repo with a few solutions, each with a separate build.gradle file, containing the dotnet section. What we would like to do is to centralize the dotnet section in a conventions file in the buildSrc directory. Similar to this Gradle user guide.

So we created: buildSrc\build.gradle

plugins {
    id 'groovy-gradle-plugin'
}

repositories {
    gradlePluginPortal() // so that external plugins can be resolved in dependencies section
}

dependencies {
    implementation 'com.github.Itiviti.dotnet:com.itiviti.dotnet:1.9.5'
}

and we created a file buildSrc\src\main\groovy\myproject.dotnet-conventions.gradle.

When we try to use this with gradle build, it says:

> Could not resolve all files for configuration ':buildSrc:compileClasspath'.
   > Could not find com.github.Itiviti.dotnet:com.itiviti.dotnet:1.9.5.
     Searched in the following locations:
       - https://plugins.gradle.org/m2/com/github/Itiviti/dotnet/com.itiviti.dotnet/1.9.5/com.itiviti.dotnet-1.9.5.pom
     If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
     Required by:
         project :buildSrc

My assumption is that the prefix 'com.github.Itiviti.dotnet:com' is not correct, as I have just made something up. Now my question: what prefix do I have to use here?

If I am totally off, please let me know too.

ngyukman commented 1 year ago

honestly I didn't test if incremental works correctly for using this plugin, you will need to have one gradle project per .sln and making them as gradle subprojects, then hopefully the plugin setup the Input source correctly and skip the task execution

but first you should go for simple, that builds a few sln and try

for your current issue, remove

dependencies {
    implementation 'com.github.Itiviti.dotnet:com.itiviti.dotnet:1.9.5'
}

and put the following inside the plugins block, as mentioned in the README

    id 'com.itiviti.dotnet'
janzwanenburg commented 1 year ago

Thanks for the reply. I have a sample with a few sln each with its own gradle.build file. That is working. But now I'd like to take the next step. Hence the question.

But if you are not sure the incremental build works ok, I am very doubtful whether this approach is mature enough for our purpose.

ngyukman commented 1 year ago

Incremental build in gradle requires Input / Output detected correctly from gradle I used in CI and always rebuild everything, thus I didn't test if the code setting Input / Output is set correctly

You can probably try updating source in one of the projects and see if the tasks are skipped correctly

Rockdell commented 10 months ago

Hey. I am currently trying to get gradle caching to work so that if you revert something you had already compiled it doesn't recompile again but unfortunately it doesn't seem to work since it always compiles the project. I can confirm that the task is not executed if the sources/destinations haven't changed but I can't get caching between runs to work. Currently in the DotnetBuild task I am just declaring sources and the destinations directory nothing more. Is this supported, and if yes, am I missing something?

ngyukman commented 9 months ago

Hi @Rockdell

gradle caching does not work with dotnet since the build is actually done by dotnet not gradle but it should support incremental build from msbuild as mentioned in https://learn.microsoft.com/en-us/visualstudio/msbuild/incremental-builds?view=vs-2022