Difference between compile and runtime configurations in Gradle - configuration

My question is a little bit common, but it is linked with Gradle too.
Why we need compile and runtime configuration?
When I compile something I need artifacts to convert my java classes in bytecode so I need compile configuration, but why is needed runtime configuration do I need something else to run my application in JVM?
Sorry if it sounds stupid, but I don't understand.

In the most common case, the artifacts needed at compile time are a subset of those needed at runtime. For example, let's say that a program called app uses library foo, and library foo internally uses library bar. Then only foo is needed to compile app, but both foo and bar are needed to run it. This is why by default, everything that you put on Gradle's compile configuration is also visible on its runtime configuration, but the opposite isn't true.

Updating the answer as per the latest gradle versions.
From gradle's official documentation at below link:
https://docs.gradle.org/current/userguide/upgrading_version_5.html
Deprecations
Dependencies should no longer be declared using the compile and runtime configurations The usage of the compile and runtime
configurations in the Java ecosystem plugins has been discouraged
since Gradle 3.4.
The implementation, api, compileOnly and runtimeOnly configurations should be used to declare dependencies and the compileClasspath and
runtimeClasspath configurations to resolve dependencies.
More so, the compile dependency configuration has been removed in the recently released Gradle 7.0 version.
If you try to use compile in your Gradle 3.4+ project you’ll get a warning like this:
Deprecated Gradle features were used in this build, making it
incompatible with Gradle 7.0. Use ‘–warning-mode all’ to show the
individual deprecation warnings.
You should always use implementation rather than compile for dependencies, and use runtimeOnly instead of runtime.
What is an implementation dependency?
When you’re building and running a Java project there are two classpaths involved:
Compile classpath – Those dependencies which are required for the JDK to be able to compile Java code into .class files.
Runtime classpath – Those dependencies which are required to actually run the compiled Java code.
When we’re configuring Gradle dependencies all we’re really doing is configuring which dependencies should appear on which classpath. Given there are only two classpaths, it makes sense that we have three options to declare our dependencies.
compileOnly – put the dependency on the compile classpath only.
runtimeOnly – put the dependency on the runtime classpath only.
implementation – put the dependency on both classpaths.
Use the implementation dependency configuration if you need the dependency to be on both the compile and runtime classpaths. If not,
consider compileOnly or runtimeOnly.

Related

Should tests run in Debug or Release configuration in dotnet core

I am using dotnet core 2+, but the question is likely much more generic.
My CI pipeline currently looks like this:
dotnet build -c Release
dotnet test
dotnet public -c Release --no-build
For the test step, it uses the default Debug configuration, therefore it also has to build the app using Debug config.
Therefore, I was wondering, whether there is any advantage in running tests using Debug rather than Release or should i just simply add dotnet test -c Release?
I believe it's possible to choose by comparing of the differences between "Debug" and "Release".
In Release mode: there are compiler's optimizations. Compiler does some low-level improvements. This leads to original code can be changed significantly in some places. (some variables and methods calls can be optimized in a non obvious way).
In Debug mode: code is not optimized, and along with final assemblies compiler produces .pdb files with are used for a step by step debugging.
As a conclusion, for tests, is better to use Release mode:
It is lighter than Debug (.pdb files are not needed).
It is faster that Debug (due to compiler's optimizations, .pdb files are not generated).
Tests are run against prod like environment.
P.S. Along with that keep an eye on preprocessor directives and config transformation if they are presented, and depend on build configuration.
Do not use Debug mode if you are not going to debug your tests. Sometimes, people need debugging the app through the tests or even debugging the test itslef. If this is not the case, go with Release mode, it is lighter.

setting correct scala version on scala ide

I'm trying to work on a project on scala IDE but I've having build problems on scala IDE.
On sbt the project builds fine. I used the eclipse sbt plugin and imported the project on scala IDE. There were build errors, which makes the ide close to useless.
One of the errors is Compiler plugin paradise_2.12.1-2.1.0.jar is cross-compiled with incompatible version for this project: 2.12.1 vs 2.12.2
I thought scala minor versions were compatible, though I see there is an exception for some experimental modules. Is the macro paradise plugin one of those exceptions?
How can I fix it? Can I tell scala IDE to use 2.12.1? Shouldn't the sbt eclipse plugin take care of that? Should I report a bug(to which project)?
The project on which I'm working defines scala version to be "2.12.1", but I'd rather not change it. I'm using scala ide version 4.6.1.
here's the settings to change the scala compiler
right click on your project -> choose "properties"
from the menu tree on the left select 'Scala compiler'
check "use project settings" if unchecked
select the appropriate Scala installation from the 'Scala Installation' drop down
close the project properties window
rebuild project
my personal peeve is that when I run the eclipse plugin command from sbt, it always resets the scala installation for my project to "
Latest 2.12 bundle (dynamic)" so I've gotten pretty use to manually resetting my scala compiler version (along with my build path source directories).
If you need to (re)set your scala library container you can also do this in the project properties window (via the "Java Build Path" -> Libraries section). You may need to do this if you don't have an explicit fixed 2.12.1 installation available as an option in the above drop down.

How do I import Primefaces 6.0 source as maven project in Eclipse?

I followed Building From Source https://github.com/primefaces/primefaces/wiki/Building-From-Source instructions. Building the SNAPSHOT version project from command works well.
However, importing it into eclipse using the Existing Maven Projects wizard gives me a lot of errors in the Problems view. I fixed the lifecycle mappings by setting all to ignore.
I realized the generated source code in the target/generated-sources/maven-jsf-plugin directory but it was not picked up by the m2e plugins as a source folder automatically. So I included it into the eclipse build path manually. But then again, many compile errors show up in the generated code.
Does anybody use eclipse as IDE for primefaces development? How do you setup the eclipse project to develop primefaces?
The eclipse project uses Java Compiler compliance level 1.5 derived from the pom.xml maven-compiler-plugin settings. Setting the Java Compiler compliance level to 1.6 solved the issue for me.

(VS13) mysqlclient.lib compiles (i think) as Static Multithreaded Debug even if the Runtime Library setting is Multithreaded Debug DLL

I'm trying to compile the mysqlclient.lib library as a Multithreaded Debug DLL. I need it in this configuration to be able to link it to my project. To give some context I will explain what have I done so far:
I cloned the MySQL repository: git clone https://github.com/mysql/mysql-server.git
I created the MySQL.sln by running CMake.
I opened the solution in Visual Studio 2013 and built it with the Runtime Library setting equal to /MDd.
I have tried to link the thus compiled library mysqlclient.lib to my project(which is compiled with /MDd) but I'm still getting the error:
mysqlclient.lib(plugin_client.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
I have run dumpbin /all mysqlclient.lib | find /i "mvscr" obtaining as a result /DEFAULTLIB:MSVCRTD which suggests that the library has been compiled as /MDd.
I have to admit that before wanting to link mysqlclient.lib to my project I was not even aware of the Runtime Library setting. At this point I don't completely understand why I'm getting the linker error above, which is why I wrote in the title that I think that the library is still getting compiled as /MTd. If anyone could point me to the right direction in order to solve my problem it would be very much appreciated.
EDIT
Reading better the MySQL documentation I found out that if my project is built as /MDd or /MD I have to link it to the libmysql.dll dynamic library. Section Compiling MySQL Clients on Microsoft Windows, second to last paragraph.
https://dev.mysql.com/doc/refman/5.6/en/c-api-building-clients.html

Why do I have to specify both 'runtime' and 'compile' for the same dependency?

I am depending on a few artifacts that I need to both compile and run my application.
According to the Gradle docs, the runtime configuration extends the compile configuration, so surely adding a dependency using runtime implies an implicit compile dependency?
At least that was my assumption, but it does not work. When just depending on the artifact using runtime, my project does not compile anymore. I literally have to:
compile 'oauth.signpost:signpost-core:1.2.1.2'
runtime 'oauth.signpost:signpost-core:1.2.1.2'
for the application to both compile and see the Signpost classes at runtime.
Am I missing something? That just doesn't look right...
Almost right. Runtime configuration, indeed, extends compile configuration (docs). It means, that any dependency added to compile configuration is available in runtime configuration (docs).
compile 'oauth.signpost:signpost-core:1.2.1.2' will be enough to get this artifact in both, runtime and compile.