This message was deleted.
# community-support
s
This message was deleted.
c
Copy code
sourceSets {
    openApi {
        java {
            srcDir(tasks.openApiGenerate.outputDir)
        }
    }
}
kind of looks like it works (would love to know why they don't create their own...)
but now how do I make main depend on that...
assuming that's how I should do this... how does immutables do this...
I think I lied
isn't generating anything
Copy code
sourceSets {
    openApi {
        java {
            srcDir(tasks.openApiGenerate)
        }
    }
}

configurations {
    main.extendsFrom(openApiCompile)
}
]
I feel like this gives a better idea of what I'm trying to do, but the
main
still does not depend on the
openApi
source set. Although at least at this point it looks like the openApi source set is pointed at the correct directory (
openapi/src/main
)
v
Copy code
main.extendsFrom(openApiCompile)
just means that all dependencies that are declared on
openApiCompile
or any it extends are also declared on
main
, but it does not imply any dependency from either to the other other than that.
The proper simple way to incorporate generated sources is this if the outputs of the task are defined properly (and the open api generation tasks can be configured to meet that criterion):
Copy code
sourceSets {
    main {
        java {
            srcDir(tasks.openApiGenerate)
        }
    }
}
This way you automatically have the generated sources for all tasks that consume sources and also have implicit task dependencies where necessary automatically.
This most probably means checkstyle will check those generated classes, yes, but for that the correct way is to configure checkstyle not to consider those files.
c
Well that didn't work because the generator generates a repository route and not a source directory
As of today our solution is we are going to make the generated code its own module. We are also going to stop generating it this way and start committing the generated code. Given the actual output now that I've read it more closely I believe that is what the intent is. It wouldn't generate build files unless they intended you to make a repository from it.
v
Well that didn't work because the generator generates a repository route and not a source directory
Let me quote myself:
and the open api generation tasks can be configured to meet that criterion
I did this already in the past myself already, so I know it works if you bend it to your will
It wouldn't generate build files unless they intended you to make a repository from it.
Not really, afair it is meant to be used as subproject or included build. Wheter you check it in or not is not relevant for that. But checking in generated files imho is always the wrong way. No file generated by the build process should ever be checked in except as very last resort imho. 🙂
c
I have no plan on generating it in build anymore
I'm going to kill that
v
I think I detailed here or on the forums already in the past how to properly bend the open api plugin to your will, you just need to find it. 🙂
c
Oh man why you got to make me do that. Realistically though one of the reasons we're doing this is because it's still using the JSR 305 jar and that needs to go away. So did you also describe on how to deal with that? Also in some cases the open API spec that we're getting is not as useful as we'd like so it is possible that being able to modify the code by hand is a better solution
c
I'll take a look tomorrow, thanks
I still like the idea of isolating the code to its own jar either way
v
Yeah, well, then maybe just use the build as-is. Or still do it like I describe but not in
main
sourceSet but a separate like you already half-way did and then depend from
main
to that
c
Yeah I tried to figure out how to make Main depend on it. No dice. I probably wouldn't use it completely as is because I'll probably throw away a lot of those root files. Like I said though at that point Gradle basically becomes just a place the store the task configuration. I wouldn't run it at build anymore. So it would only get run if we need to update from the spec.
Which is all it does now
v
You don't know to throw away those files, you can simply tell the plugin not to generate them, like I described in the link.
I don't know from the top of my head how to depend from one source set to the other anymore, long ago I did that. Maybe the simplest by now is to declare a feature variant from that source set and depend on that feature variant.
c
Yeah like I said I'll read it tomorrow. Keep in mind I did not write the initial implementation of using this plugin. I have never seen it before and it certainly doesn't seem to be documented to do what you're saying to do.... I do know that you can throw away certain files though. I'm not certain that solves all of our problems. Nothing solves the problem that the Open API spec doesn't generate all of the code that we want it to. At some point they decided that instead of creating real objects they were going to have us generate maps that stored a generic object that held something that was just object... So now we have to write our own class to serialize properly in order to actually have some type safety versus just having maps all the way down... We do not control the spec
Having one source that depend on another is actually not that hard, I only had this problem because main that doesn't seem to work like other source sets, It's somehow special...
v
In what way do you think
main
is special here? Can you show an example? It should not really be specials except that it is wired to some places.
c
can I safely get rid of the first 2 lines?
Copy code
compileJava.dependsOn tasks.openApiGenerate
sourcesJar.dependsOn tasks.openApiGenerate

sourceSets {
    main {
        java {
            srcDir(tasks.openApiGenerate)
        }
    }
}
unfortunately, this doesn't do the right thing... it's still generating the entire structure
v
> can I safely get rid of the first 2 lines? > Yes, any explicit
dependsOn
that does not have a lifecycle task on the left-hand side is a code smell anyway. And by defining the generation task as source dir, any task needing sources gets the generated sources and automatically has the necessary task dependency, that's the point. :-) > unfortunately, this doesn't do the right thing... it's still generating the entire structure > Well, try to follow what I wrote in the conversation I linked you to. Your configuration is different from what I wrote.
c
Oh yeah because I didn't link the new code entirely
oh, no I did... what is significantly different? other that me leaking stuff I shouldn't
I'm probably going to bench this for a bit though, I need to move on. Someone is trying to sabotage me at work
v
For example all the generate...false stuff and the ignore file.
I don't remember what exactly disables which parts, but iirc my configuration in the end had maybe 2 or so b extra files besides production sources
c
hmm... ok, I'll work on it more later, somehow I missed that, and/or had tried some of that in a previous incarnation
sorry, I've been doing some real DERP's lately
🤷‍♂️ 1
😄 1