// Copyright 2017 the original author or authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

[appendix]
[[potential_traps]]
== Potential Traps


[[sec:groovy_script_variables]]
=== Groovy script variables

For Gradle users it is important to understand how Groovy deals with script variables. Groovy has two types of script variables. One with a local scope and one with a script-wide scope.

++++
<sample xmlns:xi="http://www.w3.org/2001/XInclude" id="scope" dir="userguide/tutorial/groovyScope" title="Variables scope: local and script wide">
            <sourcefile file="scope.groovy"/>
            <output executable="groovy" args="scope.groovy" />
        </sample>
++++

Variables which are declared with a type modifier are visible within closures but not visible within methods.

[[sec:configuration_and_execution_phase]]
=== Configuration and execution phase

It is important to keep in mind that Gradle has a distinct configuration and execution phase (see <<build_lifecycle>>).

++++
<sample xmlns:xi="http://www.w3.org/2001/XInclude" id="mkdirTrap" dir="userguide/tutorial/mkdirTrap" title="Distinct configuration and execution phase">
            <sourcefile file="build.gradle"/>
            <output args="-q compile"/>
        </sample>
++++

As the creation of the directory happens during the configuration phase, the `clean` task removes the directory during the execution phase.
