Foros de discusión

How to parameterize the environment in Liferay Workspace

thumbnail
Charalampos Chrysikopoulos, modificado hace 7 años.

How to parameterize the environment in Liferay Workspace

Junior Member Mensajes: 79 Fecha de incorporación: 9/12/11 Mensajes recientes
Hello,

we have a liferay workspace project and we have multiple locations (per machine) for the gradle.properties. Is there a solution like the build.properties in the ant SDK, where someone could overwrite some properties by adding a new file with the os username?
The only solution now is to ignore the gradle.properties from the git...

Thanks in advance,
Harry
thumbnail
Gregory Amerson, modificado hace 7 años.

RE: How to parameterize the environment in Liferay Workspace

Liferay Legend Mensajes: 1123 Fecha de incorporación: 16/02/10 Mensajes recientes
Hey Harry,

You can use normal gradle conventions to add user/machine specific settings to ~/.gradle/gradle.properties

and those properties will be read and available to your liferay workspace build.

Does that work for you?
thumbnail
Charalampos Chrysikopoulos, modificado hace 7 años.

RE: How to parameterize the environment in Liferay Workspace

Junior Member Mensajes: 79 Fecha de incorporación: 9/12/11 Mensajes recientes
Hi Gregory,

I am new to gradle so the term "normal gradle conventions" doesn't ring a bell. I must do my homework first ;)

Do you have some suggestion what to read?
thumbnail
Gregory Amerson, modificado hace 7 años.

RE: How to parameterize the environment in Liferay Workspace

Liferay Legend Mensajes: 1123 Fecha de incorporación: 16/02/10 Mensajes recientes
Sure thing, here is a good place to read up on that: https://docs.gradle.org/current/userguide/build_environment.html

and if you want to read more about gradle in general, the user guide is very helpful: https://docs.gradle.org/current/userguide/userguide.html
thumbnail
Charalampos Chrysikopoulos, modificado hace 7 años.

RE: How to parameterize the environment in Liferay Workspace

Junior Member Mensajes: 79 Fecha de incorporación: 9/12/11 Mensajes recientes
Thanks Gregory,

so if I understand correctly, we have 3 options to set the properties:

1. from gradle.properties in project build dir.
2. from gradle.properties in gradle user home.
3. from system properties, e.g. when -Dsome.property is set on the command line.

In our case, we have a demo project base on a liferay workspace, and the whole workspace is committed in git (is this right?). So, we have, say 2 developers working on this demo, and a jenkins that does the deployments on a third environment.

Based on the above example we cannot use 1. because we have 3 environments. Case 2. could be used, so every developer could place a gradle.properties file with his own value in the setting liferay.workspace.home.dir. But what if we need to work on a new project. What value should we place in the gradle.properties file? The two projects would conflict each other...

The case 3. could be a solution if we made the builds and deploys from the command line. But we prefer to work with eclipse IDE.

In eclipse IDE, there is a preference, where you can change the gradle user home. This would be stored in the eclipse workspace, and since a liferay workspace is 1-1 with the eclipse workspace, that could help as in a workaround: we could create for example a directory in the eclipse workspace to be the project's gradle home directory, that includes the custom gradle.property. But in this case we will have the whole same jars in every liferay DXP project we create. So, this is also not a solution...

Is there any case 4? Do I understand something wrong?
thumbnail
Gregory Amerson, modificado hace 7 años.

RE: How to parameterize the environment in Liferay Workspace

Liferay Legend Mensajes: 1123 Fecha de incorporación: 16/02/10 Mensajes recientes
Charalampos Chrysikopoulos:
Thanks Gregory,

so if I understand correctly, we have 3 options to set the properties:

1. from gradle.properties in project build dir.
2. from gradle.properties in gradle user home.
3. from system properties, e.g. when -Dsome.property is set on the command line.

In our case, we have a demo project base on a liferay workspace, and the whole workspace is committed in git (is this right?).

Correct, the whole workspace is committed to git, and the /bundles folder will be ignored by default so it isn't committed.

Charalampos Chrysikopoulos:
So, we have, say 2 developers working on this demo, and a jenkins that does the deployments on a third environment.

Based on the above example we cannot use 1. because we have 3 environments. Case 2. could be used, so every developer could place a gradle.properties file with his own value in the setting liferay.workspace.home.dir.


the liferay.workspace.home.dir can be a relative path. It should just be 'bundles' by default. All 3 environements (2 developers) and (1 jenkins) can use this same relative path <git_checkout>/$liferay.workspace.home.dir, which is <git_checkout>/bundles by default.

Charalampos Chrysikopoulos:

But what if we need to work on a new project. What value should we place in the gradle.properties file? The two projects would conflict each other...

No need to worry about this, see comment above.
Charalampos Chrysikopoulos:

The case 3. could be a solution if we made the builds and deploys from the command line. But we prefer to work with eclipse IDE.

In eclipse IDE, there is a preference, where you can change the gradle user home.


Yes there is a way but I don't think that is needed in this case.

Charalampos Chrysikopoulos:
This would be stored in the eclipse workspace, and since a liferay workspace is 1-1 with the eclipse workspace, that could help as in a workaround: we could create for example a directory in the eclipse workspace to be the project's gradle home directory, that includes the custom gradle.property. But in this case we will have the whole same jars in every liferay DXP project we create. So, this is also not a solution...

Is there any case 4? Do I understand something wrong?


So yes all environments will need to share the same relative path of the liferay directory ("bundles" by default).
thumbnail
Gregory Amerson, modificado hace 7 años.

RE: How to parameterize the environment in Liferay Workspace (Respuesta)

Liferay Legend Mensajes: 1123 Fecha de incorporación: 16/02/10 Mensajes recientes
Lastly for 'per workspace user specific configuration' you can do this.

1. Edit your settings.gradle and modify it with the following:

buildscript {
	dependencies {
		classpath group: "com.liferay", name: "com.liferay.gradle.plugins.workspace", version: "1.2.4"
		classpath group: "net.saliman", name: "gradle-properties-plugin", version: "1.4.6"
	}

	repositories {
		maven {
			url "https://cdn.lfrs.sl/repository.liferay.com/nexus/content/groups/public"
		}
	}
}

apply plugin: "net.saliman.properties"
apply plugin: "com.liferay.workspace"


What we are doing is applying a 'properties' plugin that gives gradle this feature.

2. Create a file called 'gradle-local.properties' and in it you can add your user specific settings

liferay.workspace.home.dir=foobar


3. Add this gradle-local.properties to .gitignore so developers don't clash with local settings.
thumbnail
Charalampos Chrysikopoulos, modificado hace 7 años.

RE: How to parameterize the environment in Liferay Workspace

Junior Member Mensajes: 79 Fecha de incorporación: 9/12/11 Mensajes recientes
Thank you very much Gregory!

I have now all the answers I need. And some more...

You have helped me a lot.
thumbnail
Denis Signoretto, modificado hace 6 años.

RE: How to parameterize the environment in Liferay Workspace

Expert Mensajes: 375 Fecha de incorporación: 21/04/09 Mensajes recientes
Hi Greg,

I have a workspace commited on git and used by multiple developers, each one with his own local environment settings.

Do you have any suggestion about howto manage this schenario?

At the moment I've create a local-dev-<developer-name> excluded in git and setted the liferay.workspace.environment=local-dev-<developer-name> in 'gradle-local.properties' files.

Thanks,
Denis
thumbnail
Charalampos Chrysikopoulos, modificado hace 6 años.

RE: How to parameterize the environment in Liferay Workspace

Junior Member Mensajes: 79 Fecha de incorporación: 9/12/11 Mensajes recientes
Hi Denis,

you have to create a new file, named "gradle-local.properties", in the root liferay workspace project folder, and in this file you can overwrite the properties you need to change. Add this file also to the ".gitignore".

Hope it helps.
thumbnail
Gregory Amerson, modificado hace 5 años.

RE: How to parameterize the environment in Liferay Workspace

Liferay Legend Mensajes: 1123 Fecha de incorporación: 16/02/10 Mensajes recientes
Denis Signoretto:
Hi Greg,

I have a workspace commited on git and used by multiple developers, each one with his own local environment settings.

Do you have any suggestion about howto manage this schenario?

At the moment I've create a local-dev-<developer-name> excluded in git and setted the liferay.workspace.environment=local-dev-<developer-name> in 'gradle-local.properties' files.

Thanks,
Denis



Hey Denis,

Nice to hear from you again!

The previous poster is correct, use gradle-local.properties and ignore it in source control is the correct solution.

This is assuming you are using a relatively recent Liferay workspace project template so you should have this configuration in your settings.gradle:


buildscript {
	dependencies {
		classpath group: "com.liferay", name: "com.liferay.gradle.plugins.workspace", version: "1.9.0"
		classpath group: "net.saliman", name: "gradle-properties-plugin", version: "1.4.6"
	}

	repositories {
		mavenLocal()

		maven {
			url "https://cdn.lfrs.sl/repository.liferay.com/nexus/content/groups/public"
		}
	}
}

apply plugin: "net.saliman.properties"

apply plugin: "com.liferay.workspace"%


See it is adding the
net.saliman.properties
plugin gives you the
gradle-local.properties
support.
thumbnail
Denis Signoretto, modificado hace 5 años.

RE: How to parameterize the environment in Liferay Workspace

Expert Mensajes: 375 Fecha de incorporación: 21/04/09 Mensajes recientes
Hi Greg happy to hear from you,

yes I'm using workspace version 2.3.1.201711201552 that includes
 "com.liferay.gradle.plugins.workspace", version: "1.7.1"
workspace plugin.

Off topic, exists the possibility to perform a "distBundle" task that execute the same operation of distBundle[Zip|Tar] but without manually extracting the compressed generated archive? (sorry if I'm lazy ;P). I've tryed with initBundle but it doesn't do the same, e.g. it doesn't copy thrd party osgi modules.

Bye,
Denis.
thumbnail
Gregory Amerson, modificado hace 5 años.

RE: How to parameterize the environment in Liferay Workspace

Liferay Legend Mensajes: 1123 Fecha de incorporación: 16/02/10 Mensajes recientes
I see, so you want a task that will prepare the final bundle as if ready for production but just leave it as a directory so you can launch the portal.

So a task that is more than initBundle but less than distBundleZip. Is that right?
thumbnail
Gregory Amerson, modificado hace 5 años.

RE: How to parameterize the environment in Liferay Workspace

Liferay Legend Mensajes: 1123 Fecha de incorporación: 16/02/10 Mensajes recientes
hey Denis,

So you can do a couple of things

1) upgrade to workspace plugin 1.9.0
2) now you have access to a new configuration called 'providedModules' where you can put your 3rd party OSGi modules
3) then in your root build.gradle you can do something like this:


dependencies {
        providedModules group: "com.google.guava", name: "guava", version: "23.0"
}

configure([initBundle, distBundleZip]) {
    into("osgi/modules") {
        from configurations.providedModules
    }
}


Now you can run
 gradlew initBundle deploy
from root of workspace and it will build a 'bundles' folder that will have everything you need. Let me know if this does what you need it to.
thumbnail
Denis Signoretto, modificado hace 5 años.

RE: How to parameterize the environment in Liferay Workspace

Expert Mensajes: 375 Fecha de incorporación: 21/04/09 Mensajes recientes
Hi Gregory,

yes that's right, I'd like a task that can create a local directory with all deps to get an environment ready to be started.
I've updated workspace to latest version (merging if from Blade init v.3.0.0 that include workspace plugin 1.9.0).

It works!
Great and thaks for your support!!!
Denis.