In the netflix grapql code gen documentation what is the equivalent of generateJava in a kotlin project build script. And how can I specify the directory of generated codes?
Also in the below code, should i add all my domain types in the collection?
typeMapping = ["MyGraphQLType": "com.mypackage.MyJavaType"]
Related
I have a multi module gradle project. The project contains two subproject, i.e. a spring-boot application server and an npm front-end ui (which is just static javascript).
I can build both sub-projects. I can define:
implementation(project(':ui'))
in the dependencies section of the spring application and I get a running jar in the server projects build folder successfully serving the frontend.
However, I want to be able not to combine the two not within the server sub-project, but rather in the enclosing project.
I thought of something like:
build.gradle:
allprojects {
group = 'com.example.webapp'
version = '0.0.1-SNAPSHOT'
}
dependencies {
implementation(project(':server'))
implementation(project(':ui'))
}
settings.gradle:
rootProject.name = 'webapp'
include 'server', 'ui'
I think, I am completely wrong. Everything I find about gradle is either completely basic, or assumes way more than what I understood about it so far.
EDIT:
With my solution approach I am getting the following error:
A problem occurred evaluating root project 'webapp'.
Could not find method implementation() for arguments [project ':server'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
EDIT 2:
The basic idea is from https://ordina-jworks.github.io/architecture/2018/10/12/spring-boot-angular-gradle.html
The implementation not found is caused by the lack of plugins applied to your root project. The implementation configuration is created by the java plugins in Gradle.
What you are trying to achieve requires a good understanding of Gradle and all the magic provided by the Spring Boot plugin.
You are effectively trying to reproduce some of that integration in your root project, without the help of the plugins.
An approach that might be easier would be to migrate your application project to be the root project and then have the ui as a subproject.
I am using Gradle tooling API to get different insights about Gradle projects such as project tasks, Gradle version, and more.
Part of this analysis requires me to know what plugins were applied (directly and transitively) by the project.
I could not find a way to get Project’s plugins from the tooling API.
Is there a way to do it?
The tooling API is limited in how you can query a build and there's no API to list build plugins, but the tooling API allows you to add your own plugins & models which you can use to query the build.
It's a little complex, but you need to add an init script to the build (eg via init.gradle) to provide your custom model & plugin to query the build.
This is a good repo that demonstrates how to do it: https://github.com/melix/gradle-tapi-demo-artifacts
Here's some code from that repo that demonstrates how to list build artifacts with a custom plugin & model:
ModelBuilder<OutgoingArtifactsModel> customModelBuilder = connection.model(OutgoingArtifactsModel.class);
customModelBuilder.withArguments("--init-script", copyInitScript().getAbsolutePath());
OutgoingArtifactsModel model = customModelBuilder.get();
for (File artifact : model.getArtifacts()) {
System.out.println("artifact = " + artifact);
}
If you want to list plugins you can use the project.getPlugins() API.
Many Gradle plugins define project properties. For instance, the Base Plugin defines the properties archivesBaseName, distsDirName, and libsDirName.
It is my understanding that using Groovy, I'd simply access them as project.archivesBaseName and so on. But how can I access these properties using the typesafe Kotlin DSL?
Many Gradle plugins define project properties
This isn't entirely true. When you do project.someProperty, Gradle will do an exhaustive lookup as noted here.
Now let's assume a very basic Java project using the Kotlin DSL:
plugins {
java
}
repositories {
jcenter()
}
dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:5.4.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.4.2")
}
Applying the java plugin applies the following key plugins:
Applies the JavaBasePlugin here
The JavaBasePlugin applies the Base plugin here
As noted in the docs here:
The Base Plugin only adds conventions related to the creation of archives, such as ZIPs, TARs and JARs
In order words, the Base plugin set defaults for all tasks that are of type AbstractArchiveTask as seen here.
As of Gradle 5.5.1, those subclasses (tasks) are:
So back to your original question:
how can I access these properties using the typesafe Kotlin DSL?
Simply retrieve a reference to the task you are trying to configure or reference:
val jar by tasks.getting(Jar::class)
println(jar.archiveBaseName.get())
val baseConvention = convention.getPlugin(BasePluginConvention::class)
println(baseConvention.libsDirName)
println(baseConvention.distsDirName)
The reason for the extra call for .get() is due to Lazy Configuration.
For any other third party plugin, you would need to either:
Grab a reference to their extension
Grab a reference to the tasks they create
I need help in getting clarification for below mentioned points
I have a swagger json. From this I want to generate Model separately by passing java as language. api and invoker clsses by passing spring as language and want to add model jar as dependency. Because I want to use model for different projects commonly. So I want to include a build task to generate model jar every time to get latest models from json. and will issue swagger code gen command with spring as language while trying to create project. Is this correct way of handling. If not can someone let me know best of handling this.
How to handle versioning from swagger.
I am new in using swagger and spring. Please suggest me best to go
I do something similar. I have my models in a separate project which is then a dependency for a bunch of API projects. This is because the APIs sometimes call each other, so need to know about each others objects.
What I do is:
Swagger structure:
In the models project I have a swagger containing just the definitions (empty object as paths)
In the API projects I have a swagger which references the definitions in the models project
Build process
Build the models project first with generateApis = false
Build the APIs with typeMappings and ImportMappings in the config, telling them to take all the models in common from that namespace
I use the maven plugin to run the codegen. I have a pretty hacky bash script that updates the type mappings in the pom when I have added new objects to the models
I'm using the Gradle connector with a Gradle project that is downloaded from a service. I want to do some Gradle operations on that project but need some information from the project.
The downloaded project's build.gradle has some properties that I would like to extract :
group = "value0"
archivesBaseName = "value1"
version = "value2"
If I use
ProjectConnection.getModel(GradleProject.class)
I can get some values from the model but not those ones that I want (perhaps I am using it wrong?). Is there a way to extract those specific values out of the project (perhaps a different model)? I can also just do some text parsing on the build file, but I'd like that to be my last option.
The Gradle tooling API only exposes a subset of the build script information, using its own models. As far as I can tell, the properties that you are interested in are not exposed by default. However, you can expose your own custom model. For an example, see samples/toolingApi/customModel in the full Gradle distribution.